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: Ulrich Bayer <ubayer at sba-research dot org>
- To: Paul Eggert <eggert at cs dot ucla dot edu>
- Cc: <libc-alpha at sourceware dot org>
- Date: Sun, 16 Jun 2013 12:13:57 +0200
- 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> <51BB406C dot 10903 at cs dot ucla dot edu> <51BB4CC9 dot 8050402 at sba-research dot org> <51BB4F14 dot 9020603 at cs dot ucla dot edu> <51BB67E3 dot 5060103 at sba-research dot org> <51BC0184 dot 9040807 at cs dot ucla dot edu>
On 15.06.2013 07:54, Paul Eggert wrote:> On 06/14/2013 11:58 AM, Ulrich Bayer wrote:
>> CPP suppresses all warnings from system headers
>
> Ah, sorry, I'd missed that, so I guess we'll need to use #error
> after all. Too bad. How about this instead?
It is admittedly simpler. Thanks!
Now that you have simplified it, let me complicate it again. :)
One thing still bugging me is the inconsistency with other use-macros that
simply require the user to define a macro for including extra functionality.
For example, a user has learned to write #define __GNU_SOURCE instead of
#define __GNU_SOURCE 1 to request GNU extensions. Since the C11 standard
leaves __STDC_WANT_LIB_EXT1__ values other than 0 and 1 undefined, it would
make sense to map a simple #define __STDC_WANT_LIB_EXT1__ i.e., a macro
definition without a version number, to the latest version. (for the time
being: 1)
So how about the following? It's unfortunately a bit longer but from
a user perspective it's definitely preferable.
#ifdef __STDC_WANT_LIB_EXT1__
#define __DO_EXPAND(VAL) 1 ## VAL
#define __IS_EMPTY_OR_ONE(VAL) ((__DO_EXPAND(VAL) == 1) || (__DO_EXPAND(VAL) == 11))
#else
#define __DO_EXPAND(VAL) 0
#define __IS_EMPTY_OR_ONE(VAL) 0
#endif
/* Use #define __STDC_WANT_LIB_EXT1__ or #define __STDC_WANT_LIB_EXT1__ 1
to include Annex K functions. */
#if (defined __GLIBC_USE_LIB_EXT1 \
&& (__GLIBC_USE_LIB_EXT1 != __IS_EMPTY_OR_ONE(__STDC_WANT_LIB_EXT1__)))
# error "Inconsistent definition of __STDC_WANT_LIB_EXT1__"
#endif
#if __IS_EMPTY_OR_ONE(__STDC_WANT_LIB_EXT1__)
# define __GLIBC_USE_LIB_EXT1 1
#else
# define __GLIBC_USE_LIB_EXT1 0
#endif
#undef __DO_EXPAND
#undef __IS_EMPTY_OR_ONE
#if __GLIBC_USE_LIB_EXT1
/* Annex K functions are declared here. */
#endif