compiletime-assert.h
Go to the documentation of this file.
#ifndef LIBGPHOTO2_PORT_COMPILETIME_ASSERT_H
#define LIBGPHOTO2_PORT_COMPILETIME_ASSERT_H
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L))
/* C11 or later */
#include <assert.h>
#define COMPILETIME_ASSERT(CONDITION) \
static_assert((CONDITION), #CONDITION)
#define BARE_COMPILETIME_ASSERT(CONDITION) \
static_assert((CONDITION), #CONDITION)
#else
/* before C11 */
#define COMPILETIME_ASSERT(CONDITION) \
switch (0) { /* error here means assertion has failed */ \
case 0: /* error here means assertion has failed */ \
case (CONDITION): /* error here means assertion has failed */ \
break; \
}
#define MAKE_BARE_COMPILETIME_ASSERT_NAME \
MAKE_BARE_COMPILETIME_ASSERT_NAME1(COMPILETIME_ASSERT_fails_in_line, \
__LINE__)
#define MAKE_BARE_COMPILETIME_ASSERT_NAME1(BASE, PARAM) \
MAKE_BARE_COMPILETIME_ASSERT_NAME2(BASE, PARAM)
#define MAKE_BARE_COMPILETIME_ASSERT_NAME2(BASE, PARAM) \
BASE ## _ ## PARAM
#define BARE_COMPILETIME_ASSERT(CONDITION) \
void MAKE_BARE_COMPILETIME_ASSERT_NAME(void); \
void MAKE_BARE_COMPILETIME_ASSERT_NAME(void) \
{ \
COMPILETIME_ASSERT(CONDITION); \
}
#endif /* after/before C11 */
#endif /* !defined(LIBGPHOTO2_PORT_COMPILETIME_ASSERT_H) */
/*
* Local Variables:
* c-file-style:"linux"
* indent-tabs-mode:t
* End:
*/