Julius Werner | 98eeb96 | 2019-12-11 15:47:42 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */ |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 2 | |
Julius Werner | 98eeb96 | 2019-12-11 15:47:42 -0800 | [diff] [blame] | 3 | #ifndef _COMMONLIB_BSD_COMPILER_H_ |
| 4 | #define _COMMONLIB_BSD_COMPILER_H_ |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 5 | |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 6 | #ifndef __packed |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 7 | #if defined(__WIN32) || defined(__WIN64) |
| 8 | #define __packed __attribute__((gcc_struct, packed)) |
| 9 | #else |
| 10 | #define __packed __attribute__((packed)) |
| 11 | #endif |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 12 | #endif |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 13 | |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 14 | #ifndef __aligned |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 15 | #define __aligned(x) __attribute__((aligned(x))) |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 16 | #endif |
| 17 | |
| 18 | #ifndef __always_unused |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 19 | #define __always_unused __attribute__((unused)) |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 20 | #endif |
| 21 | |
| 22 | #ifndef __must_check |
Caveh Jalali | 0068a9f | 2017-08-03 15:49:09 -0700 | [diff] [blame] | 23 | #define __must_check __attribute__((warn_unused_result)) |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 24 | #endif |
| 25 | |
| 26 | #ifndef __weak |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 27 | #define __weak __attribute__((weak)) |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 28 | #endif |
| 29 | |
| 30 | #ifndef __noreturn |
Aaron Durbin | 0370bcf | 2018-09-05 09:37:11 -0600 | [diff] [blame] | 31 | #define __noreturn __attribute__((noreturn)) |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 32 | #endif |
| 33 | |
| 34 | #ifndef __always_inline |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 35 | #define __always_inline inline __attribute__((always_inline)) |
Nico Huber | d44221f | 2018-10-04 23:42:42 +0200 | [diff] [blame] | 36 | #endif |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 37 | |
Julius Werner | d371cf3 | 2015-05-22 18:09:48 -0700 | [diff] [blame] | 38 | /* This evaluates to the type of the first expression, unless that is constant |
| 39 | in which case it evalutates to the type of the second. This is useful when |
| 40 | assigning macro parameters to temporary variables, because that would |
| 41 | normally circumvent the special loosened type promotion rules for integer |
| 42 | literals. By using this macro, the promotion can happen at the time the |
| 43 | literal is assigned to the temporary variable. If the literal doesn't fit in |
| 44 | the chosen type, -Werror=overflow will catch it, so this should be safe. */ |
| 45 | #define __TYPEOF_UNLESS_CONST(expr, fallback_expr) __typeof__( \ |
| 46 | __builtin_choose_expr(__builtin_constant_p(expr), fallback_expr, expr)) |
| 47 | |
| 48 | /* This creates a unique local variable name for use in macros. */ |
| 49 | #define __TMPNAME_3(i) __tmpname_##i |
| 50 | #define __TMPNAME_2(i) __TMPNAME_3(i) |
| 51 | #define __TMPNAME __TMPNAME_2(__COUNTER__) |
| 52 | |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 53 | #endif |