H
Hallvard B Furuseth
James said:Chris said:typedef char test[
sizeof(char * 4) == 32 / CHAR_BIT
];
I understand what you're trying to do there, but wouldn't a #if/#endif
pair bracking a #error directive do what you're trying to do in a much
clearer way?
Yes, #if/#error/#endif is better when you can use preprocessor constants
for your check. Like in this case, since sizeof(char) can be dropped.
If you want to check e.g. sizeof or enum values at compile time, you
need to force a constraint violation after preprocessing. Or two
violations, since some compilers are sloppy about checking them. I
prefer to macroize that to make the actual assertion readable:
#define static_assert(name, c) \
typedef struct { int Assert_##name: 2-4*(c); } Assert_##name[2-4*(c)]
/* TODO: Port this to saner assumptions */
static_assert(supported_atomic, sizeof(sig_atomic_t) * CHAR_BIT >= 16);