JKop wrote:
Karl Heinz Buchegger posted:
It may be everything. No initialization -> undefined (except in static
cases. God how I hate those exceptions everywhere:
static int i;
i has a value of 0. Even without initialization. It's a leftover from
C)
int* jk;
Mine was a global variable. Global variables get initialized to 0, no?
If so, does a global pointer get initialized to NULL, which may or may not
be 0?
...
Hmm... You are a bit confused. When it comes to pointer initialization,
NULL acts the same way as literal '0' (or, more precisely, an integral
constant expression that evaluates to zero). So in this context it is
safe to say that NULL _is_ 0.
A pointer of type 'int*' with static storage duration gets implicitly
initialized to null-pointer value (NPV) of type 'int*'. This is not
exactly what NULL is. NULL is universal null-pointer constant (NPC)
(just like literal '0', for example). When NPC gets converted to certain
pointer type 'T*', it turns into NPV of that type. Different pointer
types might use completely different representations for their NPVs.
NPVs are not required to be represented by "all-zeroes" bit pattern.
That's why 'memset' is not guaranteed to produce NPVs in the original
example.
--
Best regards,
Andrey Tarasevich