This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: static_assert in c89 and c99


Rich Felker <dalias@libc.org> writes:

| On Wed, Feb 04, 2015 at 01:23:05PM +0100, Lars Gullik Bjønnes wrote:
>> 
>> In our sources in pre c11 we add our own assert.h and use #include_next
>> to get the proper one after having added a couple of things of our own.
>> 
>> One of those things is a static_assert defined when not compiling with
>> -std=c11, if c11 we want the one provided by glibcs assert.h.
>> 
>> test snippet:
>> 
>> --------------
>> #include <assert.h>
>> 
>> #ifdef static_assert
>> #error static_assert defined
>> #endif
>> --------------
>> 
>> gcc -D_GNU_SOURCE -std=c89 -c snippet.c
>> gcc -D_GNU_SOURCE -std=c99 -c snippet.c
>> gcc -D_GNU_SOURCE -std=c11 -c snippet.c
>> 
>> all error out, where only c11 variant is expected to do so.
>> 
>> It seems that the addition of "# define _ISOC11_SOURCE 1" (features.h)
>> to what gets defined by _GNU_SOURCE is causing this.
>
| Defining _GNU_SOUCE gives glibc permission to expose anything and
| everything. If you don't want this, don't define it. The whole point
| of _GNU_SOURCE is to free glibc from namespace constraints.

Why we use it.

>> In assert.h static_assert is always defined when __USE_ISOC11 is defined
>> and that is unconditionally defined by _ISOC11_SOURCE. For a library
>> feature that would be ok, but since static_assert is using
>> _Static_assert its usability is really controlled by the compiler and
>> -std=c11.
>> 
>> I think the static_assert define must be guarded by a check that
>> -std=c11 really is in effect.
>
| If glibc is providing static_assert using _Static_assert on compilers
| which don't implement the latter, that should probably be fixed. It
| could be done using _Static_assert conditionally on __GNUC__>=x ||
| __STDC_VERSION__>=C11, with a fallback to an old method like the dummy
| type declaration with possibly-invalid array size.

Gcc 4.6 got support for _Static_assert unconditionally.
We se the problem since we are (unfortunately) forced to use gcc 4.4.

-- 
	Lgb


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]