JKop wrote:[color=blue]
>
> Karl Heinz Buchegger posted:
>[color=green]
> > JKop wrote:[color=darkred]
> >>
> >> > More than that. Setting non-padding (value-forming) bits of a
> >> > pointer to 0 doesn't necessarily produce the null-pointer value of
> >> > corresponding type. In other words, it is not guaranteed that
> >> > elements of the array will compare equal to 'NULL' after that
> >> > 'memset'.
> >> >
> >>
> >> This I don't understand.[/color]
> >
> > It's pretty simple once you know it.
> >
> > When setting a pointer to 'doesn't point anywhere' we write
> >
> > int* pPtr = 0;
> >
> > Even if the above looks like assigning the bit pattern for 0 to a
> > pointer variable, it need not be so. A specific platform might use a
> > completely different bit pattern for describing: pointer to nowhere.
> > Well, even if a specific platform does that, we still write pPtr = 0,
> > and the compiler has to replace 0 with the bit pattern used at that
> > platform.
> >
> > Pointer_value_0 != bit_pattern_for_0
> >
> > The compiler can do this, because it knows about pointers and this
> > special case. But memset() doesn't.[/color]
>
> Interesting! I'm assuming this is in the Standard, yes?[/color]
Yes. of course
But it's not written down that way. It follows from some rules that
turn around null pointer values, null pointer constants and their
required behaviour.
[color=blue]
>
> Similarly, if you write:
>
> int* jk; //Global variable
>
> It may get 0, or it may get whatever is supposed to be a NULL pointer. That
> right?[/color]
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)
--
Karl Heinz Buchegger
kbuchegg@gascad.at