diff options
author | ed <ed@FreeBSD.org> | 2011-12-14 09:09:37 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2011-12-14 09:09:37 +0000 |
commit | 7d15ee0fa9108440bc5dbb41614f2cd01606a243 (patch) | |
tree | 681563a3472c44b9f23f776b7fa6c04bec3672a4 /sys/sys | |
parent | 3261af5d4be61ef5b85c438a756a98f4ffdd76b9 (diff) | |
download | FreeBSD-src-7d15ee0fa9108440bc5dbb41614f2cd01606a243.zip FreeBSD-src-7d15ee0fa9108440bc5dbb41614f2cd01606a243.tar.gz |
Slightly alter the C1X definitions in in cdefs.h:
- Add _Alignas(). Unfortunately this macro is only partially functional.
The C1X standard will allow both an integer and a type name to be
passed to this macro, while this macro only allows an integer. To be
portable, one must use _Alignas(_Alignof(double)) to use type names.
- Don't do _Static_assert() when __COUNTER__ is not supported. We'd
better keep this implementation robust and allow it to be used in
header files, without mysteriously breaking older compilers.
Diffstat (limited to 'sys/sys')
-rw-r--r-- | sys/sys/cdefs.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index eb7f984..784d7f0 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -222,6 +222,7 @@ * Keywords added in C1X. */ #if defined(__cplusplus) && __cplusplus >= 201103L +#define _Alignas(e) alignas(e) #define _Alignof(e) alignof(e) #define _Noreturn [[noreturn]] #define _Static_assert(e, s) static_assert(e, s) @@ -231,21 +232,23 @@ #else /* Not supported. Implement them manually. */ #ifdef __GNUC__ +#define _Alignas(e) __attribute__((__aligned__(e))) #define _Alignof(e) __alignof__(e) #define _Noreturn __attribute__((__noreturn__)) #define _Thread_local __thread #else +#define _Alignas(e) #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] +#else +#define _Static_assert(e, s) +#endif #endif #if __GNUC_PREREQ__(2, 96) |