Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Dec 2011 19:37:27 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r228477 - head/sys/sys
Message-ID:  <201112131937.pBDJbRLn064233@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Tue Dec 13 19:37:27 2011
New Revision: 228477
URL: http://svn.freebsd.org/changeset/base/228477

Log:
  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

Modified:
  head/sys/sys/cdefs.h

Modified: head/sys/sys/cdefs.h
==============================================================================
--- head/sys/sys/cdefs.h	Tue Dec 13 18:11:25 2011	(r228476)
+++ head/sys/sys/cdefs.h	Tue Dec 13 19:37:27 2011	(r228477)
@@ -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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201112131937.pBDJbRLn064233>