ON Semiconductor / mbed-os

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_cpp.cpp Source File

test_cpp.cpp

00001 #include "mbed_assert.h"
00002 #define THE_ANSWER 42
00003 
00004 // Tests for static asserts in different contexts
00005 // multiple asserts are used to garuntee no conflicts occur in generated labels
00006 
00007 // Test for static asserts in global context
00008 MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
00009         "An int must be larger than char");
00010 MBED_STATIC_ASSERT(2 + 2 == 4,
00011         "Hopefully the universe is mathematically consistent");
00012 MBED_STATIC_ASSERT(THE_ANSWER == 42,
00013         "Said Deep Thought, with infinite majesty and calm");
00014 
00015 struct test {
00016     int dummy;
00017 
00018     // Test for static asserts in struct context
00019     MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char),
00020             "An int must be larger than char");
00021     MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
00022             "Hopefully the universe is mathematically consistent");
00023     MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
00024             "Said Deep Thought, with infinite majesty and calm");
00025 
00026     MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
00027             "An int must be larger than char");
00028     MBED_STATIC_ASSERT(2 + 2 == 4,
00029             "Hopefully the universe is mathematically consistent");
00030     MBED_STATIC_ASSERT(THE_ANSWER == 42,
00031             "Said Deep Thought, with infinite majesty and calm");
00032 };
00033 
00034 MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
00035         "Static assertions should not change the size of a struct");
00036 
00037 void doit_c(void) {
00038     // Test for static asserts in function context
00039     MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
00040             "An int must be larger than char");
00041     MBED_STATIC_ASSERT(2 + 2 == 4,
00042             "Hopefully the universe is mathematically consistent");
00043     MBED_STATIC_ASSERT(THE_ANSWER == 42,
00044             "Said Deep Thought, with infinite majesty and calm");
00045 }
00046