XC8 seems to ignore negative array sizes in typedefs, a common trick for realizing static assert functionality in C. To get around this, the following code defines an unused file-scope function that declares an automatic array with negative size if the assertion fails, which XC8 properly complains about. If the assertion passes, the function gets defined, but is never called, and gets optimized out.
I disable the unused function warning to clean up the output a bit.
// disable unused function definition warnings // this will throw a negative array size when the assertion // fails at compile time; check line it was expanded from STATIC_ASSERT(1 == 1); STATIC_ASSERT(1 == 0);
this is mostly here so I can search for it later.