Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
TESTS/mbedmicro-mbed/static_assert/test_c.c@0:098463de4c5d, 2017-01-25 (annotated)
- Committer:
- group-onsemi
- Date:
- Wed Jan 25 20:34:15 2017 +0000
- Revision:
- 0:098463de4c5d
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| group-onsemi | 0:098463de4c5d | 1 | #include "mbed_assert.h" |
| group-onsemi | 0:098463de4c5d | 2 | #define THE_ANSWER 42 |
| group-onsemi | 0:098463de4c5d | 3 | |
| group-onsemi | 0:098463de4c5d | 4 | // Tests for static asserts in different contexts |
| group-onsemi | 0:098463de4c5d | 5 | // multiple asserts are used to garuntee no conflicts occur in generated labels |
| group-onsemi | 0:098463de4c5d | 6 | |
| group-onsemi | 0:098463de4c5d | 7 | // Test for static asserts in global context |
| group-onsemi | 0:098463de4c5d | 8 | MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), |
| group-onsemi | 0:098463de4c5d | 9 | "An int must be larger than char"); |
| group-onsemi | 0:098463de4c5d | 10 | MBED_STATIC_ASSERT(2 + 2 == 4, |
| group-onsemi | 0:098463de4c5d | 11 | "Hopefully the universe is mathematically consistent"); |
| group-onsemi | 0:098463de4c5d | 12 | MBED_STATIC_ASSERT(THE_ANSWER == 42, |
| group-onsemi | 0:098463de4c5d | 13 | "Said Deep Thought, with infinite majesty and calm"); |
| group-onsemi | 0:098463de4c5d | 14 | |
| group-onsemi | 0:098463de4c5d | 15 | struct test { |
| group-onsemi | 0:098463de4c5d | 16 | int dummy; |
| group-onsemi | 0:098463de4c5d | 17 | |
| group-onsemi | 0:098463de4c5d | 18 | // Test for static asserts in struct context |
| group-onsemi | 0:098463de4c5d | 19 | MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char), |
| group-onsemi | 0:098463de4c5d | 20 | "An int must be larger than char"); |
| group-onsemi | 0:098463de4c5d | 21 | MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4, |
| group-onsemi | 0:098463de4c5d | 22 | "Hopefully the universe is mathematically consistent"); |
| group-onsemi | 0:098463de4c5d | 23 | MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42, |
| group-onsemi | 0:098463de4c5d | 24 | "Said Deep Thought, with infinite majesty and calm"); |
| group-onsemi | 0:098463de4c5d | 25 | }; |
| group-onsemi | 0:098463de4c5d | 26 | |
| group-onsemi | 0:098463de4c5d | 27 | MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int), |
| group-onsemi | 0:098463de4c5d | 28 | "Static assertions should not change the size of a struct"); |
| group-onsemi | 0:098463de4c5d | 29 | |
| group-onsemi | 0:098463de4c5d | 30 | void doit_c(void) { |
| group-onsemi | 0:098463de4c5d | 31 | // Test for static asserts in function context |
| group-onsemi | 0:098463de4c5d | 32 | MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), |
| group-onsemi | 0:098463de4c5d | 33 | "An int must be larger than char"); |
| group-onsemi | 0:098463de4c5d | 34 | MBED_STATIC_ASSERT(2 + 2 == 4, |
| group-onsemi | 0:098463de4c5d | 35 | "Hopefully the universe is mathematically consistent"); |
| group-onsemi | 0:098463de4c5d | 36 | MBED_STATIC_ASSERT(THE_ANSWER == 42, |
| group-onsemi | 0:098463de4c5d | 37 | "Said Deep Thought, with infinite majesty and calm"); |
| group-onsemi | 0:098463de4c5d | 38 | } |
| group-onsemi | 0:098463de4c5d | 39 |