...
Code Block |
---|
static_assert(constant-expression, string-literal); |
Section Subclause 6.7.10 of the C Standard [ISO/IEC 9899:2011] states:
...
Code Block | ||||
---|---|---|---|---|
| ||||
struct timer {
unsigned char MODE;
unsigned int DATA;
unsigned int COUNT;
};
int func(void) {
assert(sizeof(struct timer) == sizeof(unsigned char) + sizeof(unsigned int) + sizeof(unsigned int));
}
|
Although the use of the runtime assertion is better than nothing, it needs to be placed in a function and executed. This means that it is usually far away from the definition of the actual structure to which it refers. The diagnostic occurs only at runtime and only if the code path containing the assertion is executed.
...
[Becker 2008] | |
[Eckel 2007] | |
[ISO/IEC 9899:2011] | Section Subclause 6.7.10, "Static Assertions" |
[Jones 2010] | |
[Klarer 2004] | |
[Saks 2005] | |
[Saks 2008] |
...