"John Matthews" <jm5...@...> wrote:
>
> Say:
>
> int fn1(void)
> {
> int *p = NULL;
> return !p;
> }
>
> int fn2(void)
> {
> static int *p;
> return !p;
> }
>
> On a machine where NULL is represented internally by 0,
NULL is a macro. It doesn't have a representation per se.
You should be talking in terms of 'null pointers'. NULL is
an implementation defined 'null pointer constant'. It is
not a null pointer! It will yield a null pointer if assigned
to an object of pointer type.
> both these functions will return 1.
>
> On machines where NULL is represented internally by a
> non-0 value, fn1() will still return 1, but what about
> fn2()? That is, p is initialised to 0, but is that an
> 'internal' 0 (function returns 0) or a 'pointer
> context' 0 (function returns 1)?
Initialisation is in terms of assignment, and assignments
*DO NOT* assign representations! They only assign _values_.
Any given value may potentially have multiple
representations that will compare equal.
Of course, the representation will be dependant on the
value being assigned, but even something like flg |= 1
is assigning a value, not a representation.
But to answer your question, 6.7.8p10:
...If an object that has static storage duration is
not initialized explicitly, then:
- if it has pointer type, it is initialized to a
null pointer; ...
Even a partial initialisation will initialise pointers
this way. Thus...
static struct
{
int i;
int *ip;
} x = { 42 };
...will initialise x.i to 42, and x.ip to a null pointer
constant. [Note that = {0} can be used to properly
initialise _any_ object.]
Where you might have problems is assuming that calloc()
or memset(addr, 0, n) will yield null pointers in the
objects they affect.
--
Peter