Mail Archives: djgpp/2013/08/03/09:30:17.1
On Thu, 01 Aug 2013 06:04:45 -0400, Stephen J. Turnbull
<turnbull AT sk DOT tsukuba DOT ac DOT jp> wrote:
> Rod Pemberton writes:
>
> > E.g., [C definition committees] could've specified a NULL pointer
> > always points to an emtpy string of just a null character. Such a
> > specification is unlikely to break C, since a NULL pointer just
> > needs to have a unique address. This would've allowed a NULL
> > pointer to safely function as an empty character string too.
>
> Which is an arbitrary decision,
True. But, how is that any different than specifying NULL in the
first place? Specifying that NULL exist to detect valid pointers
is an arbitrary decision too. This functionality could've been
implemented some other way or simply not at all.
> [...] because it could be a pointer to an
> arbitrary instance of *any* type.
If it's been specified by an arbitrary decision, then the pointer
points to an arbitrary instance of *one* type out of *many*, yes.
No, it wouldn't likely be a pointer to arbitrary instance of some
type other than a char. That's the only type that would serve
some purpose due to the way strings are implemented in C.
Other types don't have this issue.
> Of course some of those instances
> may be compatible with an empty string, but I don't see how you can
> guarantee they *all* will be, on all machines you might want to target
> with a C compiler.
> [...] So the decision to favor strings is arbitrary.
>
It would only add additional functionality to NULL for use as char
pointers. AISI, additional functionality for other non-char types
hasn't demonstrated any theoretical or real world need. Of course,
this apparent need only exists because strings in C are implemented
as arrays instead a complete type. I.e., they're not "first class
citizens".
Rod Pemberton
--
"... to secure these rights, governments are instituted among men,
deriving their just powers from the consent of the governed; that
whenever any form of government becomes destructive of these ends,
it is the right of the people to alter or abolish it ..."
-Thomas Jefferson, Declaration of Independence, 1776
- Raw text -