diff options
author | ed <ed@FreeBSD.org> | 2011-12-13 19:37:27 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2011-12-13 19:37:27 +0000 |
commit | cfdb54c6d44eb72c60ba7f1307226c7272f38b2c (patch) | |
tree | b97814feb3e5775a34a79296627ce01dd8198356 /sys/sys | |
parent | d0b9b8460db41f0b5895f15cab33115a5e6d2480 (diff) | |
download | FreeBSD-src-cfdb54c6d44eb72c60ba7f1307226c7272f38b2c.zip FreeBSD-src-cfdb54c6d44eb72c60ba7f1307226c7272f38b2c.tar.gz |
Make support for C1X keywords more complete.
- _Alignof(), which returns the aligment of a certain type.
- _Static_assert(), which can be used to check compile-time assertions.
- _Thread_local, which uses TLS on a variable.
MFC after: 3 months
Reviewed by: mdf
Diffstat (limited to 'sys/sys')
-rw-r--r-- | sys/sys/cdefs.h | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index e7f447d..eb7f984 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -218,15 +218,34 @@ #endif #endif - +/* + * Keywords added in C1X. + */ #if defined(__cplusplus) && __cplusplus >= 201103L +#define _Alignof(e) alignof(e) #define _Noreturn [[noreturn]] +#define _Static_assert(e, s) static_assert(e, s) +#define _Thread_local thread_local #elif defined(__STDC_VERSION__) && __STDC_VERSION__ > 201000L -/* Do nothing - _Noreturn is a keyword */ -#elif defined(__GNUC__) +/* Do nothing. They are language keywords. */ +#else +/* Not supported. Implement them manually. */ +#ifdef __GNUC__ +#define _Alignof(e) __alignof__(e) #define _Noreturn __attribute__((__noreturn__)) +#define _Thread_local __thread #else +#define _Alignof(e) __offsetof(struct { char __a; e __b; }, __b) #define _Noreturn +#define _Thread_local +#endif +#ifdef __COUNTER__ +#define _Static_assert(e, s) __Static_assert(e, __COUNTER__) +#else +#define _Static_assert(e, s) __Static_assert(e, __LINE__) +#endif +#define __Static_assert(e, c) ___Static_assert(e, c) +#define ___Static_assert(e, c) typedef char __assert ## c[(e) ? 1 : -1] #endif #if __GNUC_PREREQ__(2, 96) |