libgphoto2 photo camera library (libgphoto2) API 2.5.33
Loading...
Searching...
No Matches
compiletime-assert.h
Go to the documentation of this file.
1
28
29#ifndef LIBGPHOTO2_PORT_COMPILETIME_ASSERT_H
30#define LIBGPHOTO2_PORT_COMPILETIME_ASSERT_H
31
32
33#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L))
34/* C11 or later */
35
36#include <assert.h>
37
38/* needed for older Macs https://github.com/gphoto/libgphoto2/issues/1145 */
39#ifndef static_assert
40#define static_assert _Static_assert
41#endif
42
44#define COMPILETIME_ASSERT(CONDITION) \
45 static_assert((CONDITION), #CONDITION)
46
48#define BARE_COMPILETIME_ASSERT(CONDITION) \
49 static_assert((CONDITION), #CONDITION)
50
51#else
52/* before C11 */
53
55#define COMPILETIME_ASSERT(CONDITION) \
56 switch (0) { /* error here means assertion has failed */ \
57 case 0: /* error here means assertion has failed */ \
58 case (CONDITION): /* error here means assertion has failed */ \
59 break; \
60 }
61
62
64#define MAKE_BARE_COMPILETIME_ASSERT_NAME \
65 MAKE_BARE_COMPILETIME_ASSERT_NAME1(COMPILETIME_ASSERT_fails_in_line, \
66 __LINE__)
67
68
70#define MAKE_BARE_COMPILETIME_ASSERT_NAME1(BASE, PARAM) \
71 MAKE_BARE_COMPILETIME_ASSERT_NAME2(BASE, PARAM)
72
73
75#define MAKE_BARE_COMPILETIME_ASSERT_NAME2(BASE, PARAM) \
76 BASE ## _ ## PARAM
77
78
80#define BARE_COMPILETIME_ASSERT(CONDITION) \
81 void MAKE_BARE_COMPILETIME_ASSERT_NAME(void); \
82 void MAKE_BARE_COMPILETIME_ASSERT_NAME(void) \
83 { \
84 COMPILETIME_ASSERT(CONDITION); \
85 }
86
87#endif /* after/before C11 */
88
89
90#endif /* !defined(LIBGPHOTO2_PORT_COMPILETIME_ASSERT_H) */
91
92/*
93 * Local Variables:
94 * c-file-style:"linux"
95 * indent-tabs-mode:t
96 * End:
97 */