takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_c.c Source File

test_c.c

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 guarantee 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 
00027 MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
00028                    "Static assertions should not change the size of a struct");
00029 
00030 void doit_c(void)
00031 {
00032     // Test for static asserts in function context
00033     MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
00034                        "An int must be larger than char");
00035     MBED_STATIC_ASSERT(2 + 2 == 4,
00036                        "Hopefully the universe is mathematically consistent");
00037     MBED_STATIC_ASSERT(THE_ANSWER == 42,
00038                        "Said Deep Thought, with infinite majesty and calm");
00039 }
00040