3 Compiler-specific definitions. Note that unknown compiler is not a
6 Copyright (C) 2010-2013 Andrew Nayenko
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef COMPILER_H_INCLUDED
23 #define COMPILER_H_INCLUDED
25 #if __STDC_VERSION__ < 199901L
26 #error C99-compliant compiler is required
29 #if defined(__clang__)
31 #define PRINTF __attribute__((format(printf, 1, 2)))
32 #define NORETURN __attribute((noreturn))
33 #define PACKED __attribute__((packed))
34 #if __has_extension(c_static_assert)
35 #define USE_C11_STATIC_ASSERT
38 #elif defined(__GNUC__)
40 #define PRINTF __attribute__((format(printf, 1, 2)))
41 #define NORETURN __attribute((noreturn))
42 #define PACKED __attribute__((packed))
43 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
44 #define USE_C11_STATIC_ASSERT
55 #ifdef USE_C11_STATIC_ASSERT
56 #define STATIC_ASSERT(cond) _Static_assert(cond, #cond)
58 #define CONCAT2(a, b) a ## b
59 #define CONCAT1(a, b) CONCAT2(a, b)
60 #define STATIC_ASSERT(cond) \
61 extern void CONCAT1(static_assert, __LINE__)(int x[(cond) ? 1 : -1])
64 #endif /* ifndef COMPILER_H_INCLUDED */