nullplan wrote:
sj95126 wrote:
(in C, static_assert seems to be C++)
Honestly, I wasn't quite sure of the state of static_assert in C, but in the past I got a lot of mileage out of:
Code:
#define static_assert(c) do { extern char sa[2 * !!(c) - 1]; } while (0)
I saw some examples similar to that but the limitation was that you couldn't use it outside functions, because it contain a statement. The advantage to this other approach is that I can put the asserts in the header file, immediately after the struct definition and offset #defines, so they're logically grouped together.
Anyway, there's multiple ways to do it, and some are certainly more portable and backwards-compatible with others, but I'm just happy to have something that will help, so I can stop worrying I'll accidentally transpose struct offsets and create weird bugs.