This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC][PATCH v3] Initial support for C11 Annex K Bounds checking functions
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Ulrich Bayer <ubayer at sba-research dot org>
- Cc: libc-alpha at sourceware dot org, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Fri, 14 Jun 2013 09:10:20 -0700
- Subject: Re: [RFC][PATCH v3] Initial support for C11 Annex K Bounds checking functions
- References: <51B1B444 dot 8080608 at sba-research dot org> <51B43794 dot 1020300 at cs dot ucla dot edu> <51BAF465 dot 4010203 at sba-research dot org>
On 06/14/2013 03:45 AM, Ulrich Bayer wrote:
> we should not try to check for inconsistent definitions of
> __STDC_WANT_LIB_EXT1__ but check whether Annex K functionality is included consistently
> or not inside a preprocessor translation unit.
Sure, that's fine and is arguably a better interpretation anyway.
The implementation you gave is a bit long, though -- here's something
simpler:
/* Check that C11 Annex K declarations are consistently either included
or excluded for all standard headers. */
#if defined __STDC_WANT_LIB_EXT1__ && __STDC_WANT_LIB_EXT1__ == 1
# define __GLIBC_USE_LIB_EXT1 1
#else
# define __GLIBC_USE_LIB_EXT1 0
#endif
(Heh. This is probably what the standard-writers had in mind, if
they thought about the problem at all....)
The rest of the .h file can use "#if __GLIBC_USE_LIB_EXT1" to decide
whether to include _s declarations.
> For example, the draft implementation will not catch the following inconsistent definition:
> #define __STDC_WANT_LIB_EXT1__ 2
> #include "string.h">
> #define __STDC_WANT_LIB_EXT1__ 0
> #include "stdlib.h"
That's OK in my book, since #defining __STDC_WANT_LIB_EXT1__
to a value other than 0 or 1 has undefined behavior. Admittedly
there is some ambiguity here, since it's not clear whether the
"is defined differently" rule trumps the undefined-behavior rule;
but as we can easily implement the check if we only have to worry about
0 or 1 or not-#defined, let's do that, and we can save for later
the fine points of whether C-standard pedanticism requires GCC extensions.