bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | compiler.h (09.06.13) |
| 3 | Compiler-specific definitions. Note that unknown compiler is not a |
| 4 | showstopper. |
| 5 | |
| 6 | Free exFAT implementation. |
bigbiff bigbiff | 2e33c5e | 2014-09-04 20:58:41 -0400 | [diff] [blame] | 7 | Copyright (C) 2010-2014 Andrew Nayenko |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation, either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License along |
| 20 | with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | */ |
| 23 | |
| 24 | #ifndef COMPILER_H_INCLUDED |
| 25 | #define COMPILER_H_INCLUDED |
| 26 | |
bigbiff bigbiff | 2e33c5e | 2014-09-04 20:58:41 -0400 | [diff] [blame] | 27 | /* |
| 28 | #if __STDC_VERSION__ < 199901L |
| 29 | #error C99-compliant compiler is required |
| 30 | #endif |
| 31 | */ |
| 32 | |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 33 | #if defined(__clang__) |
| 34 | |
| 35 | #define PRINTF __attribute__((format(printf, 1, 2))) |
| 36 | #define NORETURN __attribute__((noreturn)) |
| 37 | #define PACKED __attribute__((packed)) |
| 38 | #if __has_extension(c_static_assert) |
| 39 | #define USE_C11_STATIC_ASSERT |
| 40 | #endif |
| 41 | |
| 42 | #elif defined(__GNUC__) |
| 43 | |
| 44 | #define PRINTF __attribute__((format(printf, 1, 2))) |
| 45 | #define NORETURN __attribute__((noreturn)) |
| 46 | #define PACKED __attribute__((packed)) |
| 47 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) |
| 48 | #define USE_C11_STATIC_ASSERT |
| 49 | #endif |
| 50 | |
| 51 | #else |
| 52 | |
| 53 | #define PRINTF |
| 54 | #define NORETURN |
| 55 | #define PACKED |
| 56 | |
| 57 | #endif |
| 58 | |
| 59 | #ifdef USE_C11_STATIC_ASSERT |
| 60 | #define STATIC_ASSERT(cond) _Static_assert(cond, #cond) |
| 61 | #else |
| 62 | #define CONCAT2(a, b) a ## b |
| 63 | #define CONCAT1(a, b) CONCAT2(a, b) |
| 64 | #define STATIC_ASSERT(cond) \ |
| 65 | extern void CONCAT1(static_assert, __LINE__)(int x[(cond) ? 1 : -1]) |
| 66 | #endif |
| 67 | |
| 68 | #endif /* ifndef COMPILER_H_INCLUDED */ |