-
WikiChip
WikiChip
-
Architectures
Popular x86
-
Intel
- Client
- Server
- Big Cores
- Small Cores
-
AMD
Popular ARM
-
ARM
- Server
- Big
- Little
-
Cavium
-
Samsung
-
-
Chips
Popular Families
-
Ampere
-
Apple
-
Cavium
-
HiSilicon
-
MediaTek
-
NXP
-
Qualcomm
-
Renesas
-
Samsung
-
From WikiChip
Difference between revisions of "c/assert.h/static assert"
(→Description) |
|||
Line 29: | Line 29: | ||
[[Category:C standard library]] | [[Category:C standard library]] | ||
[[Category:assert.h - C]] | [[Category:assert.h - C]] | ||
+ | [[Category:Assertion - C]] |
Revision as of 18:27, 1 December 2013
<assert.h> C Header |
Macros: |
C Standard Library
The static_assert macro, which is part of <assert.h>, is a convenient object-like macro name that expands to the _Static_assert keyword.
I.E.,
#include <assert.h>
#define static_assert _Static_assert
Description
The static_assert object-like macro expands to the _Static_assert, a keyword added in C11 to provide compile-time assertion.
Example
#include <assert.h>
static_assert(sizeof(int) == 4, "Code relies on int being exactly 4 bytes");
int main(void)
{
return 0;
}
On a machine where sizeof (int) is not 4, a constraint violation occurs. On such implementations, a diagnostic message is printed similar to the one below:
example.c:3:1: error: static assertion failed "Code relies on int being exactly 4 bytes"