2016-10-21 19:28:37 +00:00
|
|
|
#include "mbed_assert.h"
|
|
|
|
#define THE_ANSWER 42
|
|
|
|
|
|
|
|
// Tests for static asserts in different contexts
|
2018-01-16 21:08:14 +00:00
|
|
|
// multiple asserts are used to guarantee no conflicts occur in generated labels
|
2016-10-21 19:28:37 +00:00
|
|
|
|
|
|
|
// Test for static asserts in global context
|
|
|
|
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
|
2018-07-27 09:17:07 +00:00
|
|
|
"An int must be larger than char");
|
2016-10-21 19:28:37 +00:00
|
|
|
MBED_STATIC_ASSERT(2 + 2 == 4,
|
2018-07-27 09:17:07 +00:00
|
|
|
"Hopefully the universe is mathematically consistent");
|
2016-10-21 19:28:37 +00:00
|
|
|
MBED_STATIC_ASSERT(THE_ANSWER == 42,
|
2018-07-27 09:17:07 +00:00
|
|
|
"Said Deep Thought, with infinite majesty and calm");
|
2016-10-21 19:28:37 +00:00
|
|
|
|
|
|
|
struct test {
|
|
|
|
int dummy;
|
|
|
|
|
|
|
|
// Test for static asserts in struct context
|
|
|
|
MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char),
|
2018-07-27 09:17:07 +00:00
|
|
|
"An int must be larger than char");
|
2016-10-21 19:28:37 +00:00
|
|
|
MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
|
2018-07-27 09:17:07 +00:00
|
|
|
"Hopefully the universe is mathematically consistent");
|
2016-10-21 19:28:37 +00:00
|
|
|
MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
|
2018-07-27 09:17:07 +00:00
|
|
|
"Said Deep Thought, with infinite majesty and calm");
|
2016-10-21 19:28:37 +00:00
|
|
|
|
|
|
|
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
|
2018-07-27 09:17:07 +00:00
|
|
|
"An int must be larger than char");
|
2016-10-21 19:28:37 +00:00
|
|
|
MBED_STATIC_ASSERT(2 + 2 == 4,
|
2018-07-27 09:17:07 +00:00
|
|
|
"Hopefully the universe is mathematically consistent");
|
2016-10-21 19:28:37 +00:00
|
|
|
MBED_STATIC_ASSERT(THE_ANSWER == 42,
|
2018-07-27 09:17:07 +00:00
|
|
|
"Said Deep Thought, with infinite majesty and calm");
|
2016-10-21 19:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
|
2018-07-27 09:17:07 +00:00
|
|
|
"Static assertions should not change the size of a struct");
|
2016-10-21 19:28:37 +00:00
|
|
|
|
2018-07-27 09:17:07 +00:00
|
|
|
void doit_c(void)
|
|
|
|
{
|
2016-10-21 19:28:37 +00:00
|
|
|
// Test for static asserts in function context
|
|
|
|
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
|
2018-07-27 09:17:07 +00:00
|
|
|
"An int must be larger than char");
|
2016-10-21 19:28:37 +00:00
|
|
|
MBED_STATIC_ASSERT(2 + 2 == 4,
|
2018-07-27 09:17:07 +00:00
|
|
|
"Hopefully the universe is mathematically consistent");
|
2016-10-21 19:28:37 +00:00
|
|
|
MBED_STATIC_ASSERT(THE_ANSWER == 42,
|
2018-07-27 09:17:07 +00:00
|
|
|
"Said Deep Thought, with infinite majesty and calm");
|
2016-10-21 19:28:37 +00:00
|
|
|
}
|
|
|
|
|