Pages

Saturday, December 26, 2009

Static Assert

Today I realized that my framework is missing static asserts (compile-time assertions). This is often implemented as a template class but I was aiming for the most minimal solution that I could come up with. After thinking for a bit I ended up writing this. It can not get simpler than this and seems to work just fine in GCC 4 and Visual Studio 2009.

#define STATICASSERT(p) typedef int _staticassert_test[p?1:-1]

Usage example

STATICASSERT(sizeof(uint32) == 4);

No comments:

Post a Comment