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.
mbed-os/TESTS/mbedmicro-mbed/static_assert/test_cpp.cpp@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | #include "mbed_assert.h" |
kadonotakashi | 0:8fdf9a60065b | 2 | #define THE_ANSWER 42 |
kadonotakashi | 0:8fdf9a60065b | 3 | |
kadonotakashi | 0:8fdf9a60065b | 4 | // Tests for static asserts in different contexts |
kadonotakashi | 0:8fdf9a60065b | 5 | // multiple asserts are used to guarantee no conflicts occur in generated labels |
kadonotakashi | 0:8fdf9a60065b | 6 | |
kadonotakashi | 0:8fdf9a60065b | 7 | // Test for static asserts in global context |
kadonotakashi | 0:8fdf9a60065b | 8 | MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), |
kadonotakashi | 0:8fdf9a60065b | 9 | "An int must be larger than char"); |
kadonotakashi | 0:8fdf9a60065b | 10 | MBED_STATIC_ASSERT(2 + 2 == 4, |
kadonotakashi | 0:8fdf9a60065b | 11 | "Hopefully the universe is mathematically consistent"); |
kadonotakashi | 0:8fdf9a60065b | 12 | MBED_STATIC_ASSERT(THE_ANSWER == 42, |
kadonotakashi | 0:8fdf9a60065b | 13 | "Said Deep Thought, with infinite majesty and calm"); |
kadonotakashi | 0:8fdf9a60065b | 14 | |
kadonotakashi | 0:8fdf9a60065b | 15 | struct test { |
kadonotakashi | 0:8fdf9a60065b | 16 | int dummy; |
kadonotakashi | 0:8fdf9a60065b | 17 | |
kadonotakashi | 0:8fdf9a60065b | 18 | // Test for static asserts in struct context |
kadonotakashi | 0:8fdf9a60065b | 19 | MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char), |
kadonotakashi | 0:8fdf9a60065b | 20 | "An int must be larger than char"); |
kadonotakashi | 0:8fdf9a60065b | 21 | MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4, |
kadonotakashi | 0:8fdf9a60065b | 22 | "Hopefully the universe is mathematically consistent"); |
kadonotakashi | 0:8fdf9a60065b | 23 | MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42, |
kadonotakashi | 0:8fdf9a60065b | 24 | "Said Deep Thought, with infinite majesty and calm"); |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), |
kadonotakashi | 0:8fdf9a60065b | 27 | "An int must be larger than char"); |
kadonotakashi | 0:8fdf9a60065b | 28 | MBED_STATIC_ASSERT(2 + 2 == 4, |
kadonotakashi | 0:8fdf9a60065b | 29 | "Hopefully the universe is mathematically consistent"); |
kadonotakashi | 0:8fdf9a60065b | 30 | MBED_STATIC_ASSERT(THE_ANSWER == 42, |
kadonotakashi | 0:8fdf9a60065b | 31 | "Said Deep Thought, with infinite majesty and calm"); |
kadonotakashi | 0:8fdf9a60065b | 32 | }; |
kadonotakashi | 0:8fdf9a60065b | 33 | |
kadonotakashi | 0:8fdf9a60065b | 34 | MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int), |
kadonotakashi | 0:8fdf9a60065b | 35 | "Static assertions should not change the size of a struct"); |
kadonotakashi | 0:8fdf9a60065b | 36 | |
kadonotakashi | 0:8fdf9a60065b | 37 | void doit_c(void) |
kadonotakashi | 0:8fdf9a60065b | 38 | { |
kadonotakashi | 0:8fdf9a60065b | 39 | // Test for static asserts in function context |
kadonotakashi | 0:8fdf9a60065b | 40 | MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), |
kadonotakashi | 0:8fdf9a60065b | 41 | "An int must be larger than char"); |
kadonotakashi | 0:8fdf9a60065b | 42 | MBED_STATIC_ASSERT(2 + 2 == 4, |
kadonotakashi | 0:8fdf9a60065b | 43 | "Hopefully the universe is mathematically consistent"); |
kadonotakashi | 0:8fdf9a60065b | 44 | MBED_STATIC_ASSERT(THE_ANSWER == 42, |
kadonotakashi | 0:8fdf9a60065b | 45 | "Said Deep Thought, with infinite majesty and calm"); |
kadonotakashi | 0:8fdf9a60065b | 46 | } |
kadonotakashi | 0:8fdf9a60065b | 47 |