[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CCompileTimeAssert
The trick to this method is that an array cannot be of size zero.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CCompileTimeAssert
(C) assert at compile-time
There is a way to do an assert at ?compile-time using a temporary array.The trick to this method is that an array cannot be of size zero.
int main() { STATIC_ASSERT( 1 + 1 == 2 ); //The line below will give the following compile-time error: // [C++ Error] : Array must have at least one element //STATIC_ASSERT( 1 + 2 == 2 ); }
- define STATIC_ASSERT(x) { const char temp[ (((x) == 0) ? 0 : 1) ] = {'\0'}; }
'Compile time assert' links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
