Mail Archives: djgpp/2013/08/03/11:55:00
Rod Pemberton writes:
> 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?
All I'm saying is, look at
char *a = NULL;
char *b = "This is a pen.\n";
char *c = b + strlen(b);
char *d = malloc(255);
char *e = "";
and tell me "which of these things is not like the others?"
> 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.
Huh? Now you're speaking in non sequiturs. How often do you see
idioms like:
void footloose_and_fancy_free (double **dp) {
free (*dp);
*dp = NULL;
}
And I personally find it useful that on most OSes (*NULL) kills your
program, no matter what type of pointer NULL has been coerced to.
This has saved me from doing something stupid many times.
> It would only add additional functionality to NULL for use as char
> pointers.
It doesn't add any functionality. See variable "e" above. It simply
allows programmers to make mistakes with strings they couldn't make
with other pointer types.
If you want the functionality you talk about, it's easy enough to get
it without forcing implementations to do something bizarre with NULL.
Just poke a zero into memory somewhere and get a pointer to it. Give
that pointer a name:
char *empty_string = "";
- Raw text -