|
Message-ID: <20130109215327.GM4468@port70.net> Date: Wed, 9 Jan 2013 22:53:27 +0100 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com Subject: Re: NULL * 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
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.