Re: [dwm] malloc'ed client in manage()

From: Nicolas Martyanoff <khaelin_AT_gmail.com>
Date: Sun, 7 Sep 2008 16:17:37 +0200

On Sun, 7 Sep 2008 13:53:11 +0200
"Szabolcs Nagy" <nszabolcs_AT_gmail.com> wrote:

> On 9/7/08, Nicolas Martyanoff <khaelin_AT_gmail.com> wrote:
> > I think it's quite explicit: the NULL macro expands to 0.
>
> NULL macro does not necessaryly expands to 0, but this is basic
> knowledge look it up in the standard.
>
> what am i concerned about is the internal null pointer representation
> (which has nothing to do wether NULL is defined 0 or not)
"NULL is a macro that expands to the
implementation-defined null pointer constant. [7.17.3]"
If NULL expands to 0, then basic logic tells me that the null pointer
constant is 0; if I'm making a logic error, what is it ?

> it is explicitely stated in c99 that there might be architectures
> where memset(&p, 0, sizeof(p)) is not equivalent to p=0;
The standard contains ambiguities, everybody knows that; if K&R 2 tells
NULL expands to 0, and the C standard tells that NULL expands to the
null pointer constant, then I think we can assume that setting a pointer
to 0 is ok.

Therefore:

struct foo {
        int i;
        void *ptr;
}

struct foo bar;
memset(&bar, 0, sizeof(struct foo));

Will get bar.i == 0, and foo.ptr == NULL.

Now, another idea is to find an existing architecture where the null
pointer representation is NOT 0. To be honest, if such an architecture
exists, then a lot of softwares won't work on it. (and K&R 2 will be
wrong...)

-- 
Nicolas Martyanoff
   http://codemore.org
   khaelin_AT_gmail.com

Received on Sun Sep 07 2008 - 14:17:37 UTC

This archive was generated by hypermail 2.2.0 : Sun Sep 07 2008 - 14:24:07 UTC