Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 9 Jan 2013 22:17:28 +0000
From: Rob <robpilling@...il.com>
To: musl@...ts.openwall.com
Subject: Re: NULL

On Wed, Jan 09, 2013 at 10:53:27PM +0100, Szabolcs Nagy wrote:
> * Rob <robpilling@...il.com> [2013-01-09 21:11:28 +0000]:
> > On Wed, Jan 09, 2013 at 10:36:30AM -0500, Rich Felker wrote:
> > > 	char s[1][1+(int)NULL];
> > > 	int i = 0;
> > > 	return sizeof s[i++], i;
> > 
> > Magic... is `s' a VLA here? My mind is boggled because
> > __builtin_constant_p(1+(int)NULL) returns 1, and I can't think of any
> > reason why the sizeof is evaluated.
> > 
> > Also, seeing that clang and tcc return 0 in all cases, is this a bug in
> > both of them?
> 
> sizeof evaluates its argument if and only if it is a vla
> (c11 6.5.3.4p2)
> 
> in c99 (and c11) vla is created if the size in the array
> declarator is not an "integer constant expression"
> (c11 6.7.6.2p4)
> 
> eg '1 + (int)(void*)0' is not an integer constant expression
> because of the pointer cast, but '1 + (int)0' is
> (c11 6.6p6)
> 
> hence sizeof s[i++] evaluates the argument if NULL has a pointer
> cast in it

Ah, thanks for the explanation.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.