This is the mail archive of the
mailing list for the glibc project.
Re: static_assert in c89 and c99
- From: larsbj at gullik dot org (Lars Gullik Bjønnes)
- To: libc-alpha at sourceware dot org
- Date: Thu, 05 Feb 2015 10:59:07 +0100
- Subject: Re: static_assert in c89 and c99
- Authentication-results: sourceware.org; auth=none
- References: <87wq3x27di dot fsf at black dot gullik dot net> <20150204143535 dot GV23507 at brightrain dot aerifal dot cx>
Rich Felker <email@example.com> 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
>> 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
>> 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.