libgphoto2 photo camera library (libgphoto2) API: libgphoto2_port/libgphoto2_port/compiletime-assert.h Source File

libgphoto2 photo camera library (libgphoto2) API 2.5.32

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
39#define COMPILETIME_ASSERT(CONDITION) \
40 static_assert((CONDITION), #CONDITION)
41
43#define BARE_COMPILETIME_ASSERT(CONDITION) \
44 static_assert((CONDITION), #CONDITION)
45
46#else
47/* before C11 */
48
50#define COMPILETIME_ASSERT(CONDITION) \
51 switch (0) { /* error here means assertion has failed */ \
52 case 0: /* error here means assertion has failed */ \
53 case (CONDITION): /* error here means assertion has failed */ \
54 break; \
55 }
56
57
59#define MAKE_BARE_COMPILETIME_ASSERT_NAME \
60 MAKE_BARE_COMPILETIME_ASSERT_NAME1(COMPILETIME_ASSERT_fails_in_line, \
61 __LINE__)
62
63
65#define MAKE_BARE_COMPILETIME_ASSERT_NAME1(BASE, PARAM) \
66 MAKE_BARE_COMPILETIME_ASSERT_NAME2(BASE, PARAM)
67
68
70#define MAKE_BARE_COMPILETIME_ASSERT_NAME2(BASE, PARAM) \
71 BASE ## _ ## PARAM
72
73
75#define BARE_COMPILETIME_ASSERT(CONDITION) \
76 void MAKE_BARE_COMPILETIME_ASSERT_NAME(void); \
77 void MAKE_BARE_COMPILETIME_ASSERT_NAME(void) \
78 { \
79 COMPILETIME_ASSERT(CONDITION); \
80 }
81
82#endif /* after/before C11 */
83
84
85#endif /* !defined(LIBGPHOTO2_PORT_COMPILETIME_ASSERT_H) */
86
87/*
88 * Local Variables:
89 * c-file-style:"linux"
90 * indent-tabs-mode:t
91 * End:
92 */