OSDN Git Service

Use C11 _Static_assert if it is supported by a compiler.
[android-x86/external-exfat.git] / libexfat / compiler.h
1 /*
2         compiler.h (09.06.13)
3         Compiler-specific definitions. Note that unknown compiler is not a
4         showstopper.
5
6         Copyright (C) 2010-2013  Andrew Nayenko
7
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.
12
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.
17
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/>.
20 */
21
22 #ifndef COMPILER_H_INCLUDED
23 #define COMPILER_H_INCLUDED
24
25 #if __STDC_VERSION__ < 199901L
26 #error C99-compliant compiler is required
27 #endif
28
29 #if defined(__clang__)
30
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
36 #endif
37
38 #elif defined(__GNUC__)
39
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
45 #endif
46
47 #else
48
49 #define PRINTF
50 #define NORETURN
51 #define PACKED
52
53 #endif
54
55 #ifdef USE_C11_STATIC_ASSERT
56 #define STATIC_ASSERT(cond) _Static_assert(cond, #cond)
57 #else
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])
62 #endif
63
64 #endif /* ifndef COMPILER_H_INCLUDED */