OSDN Git Service

Use C11 _Static_assert if it is supported by a compiler.
authorresver@gmail.com <resver@gmail.com@60bc1c72-a15a-11de-b98f-4500b42dc123>
Fri, 21 Jun 2013 17:46:03 +0000 (17:46 +0000)
committerresver@gmail.com <resver@gmail.com@60bc1c72-a15a-11de-b98f-4500b42dc123>
Fri, 21 Jun 2013 17:46:03 +0000 (17:46 +0000)
git-svn-id: http://exfat.googlecode.com/svn/trunk@361 60bc1c72-a15a-11de-b98f-4500b42dc123

libexfat/compiler.h

index 45e8581..b52103b 100644 (file)
 #error C99-compliant compiler is required
 #endif
 
-#if defined(__GNUC__) /* this includes Clang */
+#if defined(__clang__)
 
 #define PRINTF __attribute__((format(printf, 1, 2)))
 #define NORETURN __attribute((noreturn))
 #define PACKED __attribute__((packed))
+#if __has_extension(c_static_assert)
+#define USE_C11_STATIC_ASSERT
+#endif
+
+#elif defined(__GNUC__)
+
+#define PRINTF __attribute__((format(printf, 1, 2)))
+#define NORETURN __attribute((noreturn))
+#define PACKED __attribute__((packed))
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#define USE_C11_STATIC_ASSERT
+#endif
 
 #else
 
 
 #endif
 
+#ifdef USE_C11_STATIC_ASSERT
+#define STATIC_ASSERT(cond) _Static_assert(cond, #cond)
+#else
 #define CONCAT2(a, b) a ## b
 #define CONCAT1(a, b) CONCAT2(a, b)
 #define STATIC_ASSERT(cond) \
        extern void CONCAT1(static_assert, __LINE__)(int x[(cond) ? 1 : -1])
+#endif
 
 #endif /* ifndef COMPILER_H_INCLUDED */