Nicolas Martyanoff wrote:
> On Sun, 7 Sep 2008 11:25:53 +0200
> "Szabolcs Nagy" <nszabolcs_AT_gmail.com> wrote:
>
> > On 9/6/08, Filippo Erik Negroni <f.e.negroni_AT_googlemail.com> wrote:
> > > A preferable, safer and more portable way of achieving such
> > > initialisation is to use the compiler's static initialisation.
> >
> > is it because of null pointer might not be represented as zeros?
> I don't think so.
>
> K&R, 2nd Ed. page 102:
> "Pointers and integers are not interchangeable. Zero is the sole
> exception: the constant zero may be assigned to a pointer, and a
> pointer may be compared with the constant zero. The symbolic constant
> NULL is often used in place of zero, as a mnemonic to indicate that
> this is a special value for a pointer"
>
> I think it's quite explicit: the NULL macro expands to 0.
Does anyone know whether there are architectures where NULL is not equal
to 0?
See ISO/IEC 9899:TC2 Section 7.17.3:
"The macros are NULL which expands to an implementation-defined null
pointer constant and; ..."
See ISO/IEC 9899:TC2 Section 6.3.2.3.3:
"An integer constant expression with the value 0, or such an
expression cast to type void *, is called a null pointer constant."
Seems like a contradiction in the C99 standard (I have to admit that my
version is a Committee Draft).
See ISO/IEC 14882:1998 and ISO/IEC 14882:2003 Section 4.10:
"A null pointer constant is an integer constant expression (5.19)
rvalue of integer type that evaluates to zero."
See ISO/IEC 14882:1998 and ISO/IEC 14882:2003 Section 18 Footnote 180:
"Possible definitions include 0 and 0L, but not (void *)0."
And this sounds like a conflict between C and C++.
But anyhow it seems that you can't do this reliably, because s isn't
used by memset as a pointer.
memset(&s, 0, sizeof(s));
where s is a struct.
According to ISO/IEC 9899:TC2 Section 6.7.8.1 and Section 6.7.8.10 this
would be correct:
s = {0}; or s = 0;
Anyhow it's not working with gcc.
Regards,
Matthias-Christian
Received on Sun Sep 07 2008 - 12:39:29 UTC
This archive was generated by hypermail 2.2.0 : Sun Sep 07 2008 - 12:48:04 UTC