Mail Archives: djgpp/2013/08/01/04:15:16
On Wed, 31 Jul 2013 09:45:14 -0400, Stephen J. Turnbull
<turnbull AT sk DOT tsukuba DOT ac DOT jp> wrote:
> Rod Pemberton writes:
>
> > > It is not possible to give a consistent specification of what
> > > happens when NULL is passed to a function,
>
> "Consistent" may be a bad word, [...]
I don't think the use of "consistent" is the issue here.
It was clearly the use of "not possible". It's entirely
possible to specify something consistent. I'll do so at
the end of this post.
> but my point is that (pointer to char)
> and (NULL) have very different semantics.
What ...?
Do you understand what a NULL pointer actually is?
For some insight, see these posts:
https://groups.google.com/d/msg/comp.std.c/ez822gwxxYA/Jt94XH7AVacJ
https://groups.google.com/d/msg/comp.lang.c/CWc7ti0NUsc/z2RdZlWzlusJ
> The memory referenced by
> the latter can be neither accessed nor mutated,
Untrue.
A NULL pointer can and does point to accessable memory for most C
compilers.
However, the C language is not required to make access those memory regions
available via a NULL pointer.
The only requirement for NULL (when implemented as a pointer) is that the
pointer value for it does not correspond to the address of any other
objects
in the C object space, i.e., no address collision. Typically, this is
pointer
or address to memory location zero, but it's not required to be. It can be
*any* value as long as no other C object has that same address.
> [...] so no computations can be done with it.
That depends on whether a NULL is equivalent to a void pointer or a
constant.
That depends on the generation of the C specification.
If NULL's type is a void pointer, it is (losslessly) converted to a char
pointer when passed into a function for a char pointer argument. I.e.,
after the conversion, it functions as a char pointer in the function.
> In order to associate an array of chars with NULL,
> you need to make an arbitrary decision.
>
I don't.
As stated, they ("the authors of the various C specifications") didn't
specify.
> > It sure is _possible_. It just wasn't done. That's entirely
> > different than actually *not* being able to specify something.
>
> Of course it's possible to specify "something".
Exactly, it's _possible_ to specify "something".
Unfortunately, that's contrary to your prior statement.
E.g., they 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.
Rod Pemberton
- Raw text -