arrays of size 0 are no problem for gcc both in C and C++, so you should
use something like
#define ct_assert(x) typedef char _ct_assert__[(x)? 1 : -1];
tamlin(a)algonet.se schrieb:
Actually, I'd say the stupidity is in using a
runtime assert, when a
compile-time assert will do the trick (not using CPU at runtime, while
enforcing the condition).
Unless memory fails me, in C++ you can implement ct_assert(x) like:
typedef char[x!=0] foo;
as an array of size zero is an error.
How does current C compilers react to typedefs of zero-sized arrays?
Sure, one can't use it exactly as in C++, but it could still be useful
to at least know about this idiom.
Problems should be trapped as early as possible.