diff --git a/makefile b/makefile index 4f8ebb6..ab013b5 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ CC := gcc -CFLAGS := -Wall -Wextra -O2 -fsanitize=address +CFLAGS := -Wall -Wextra -Wno-override-init -O2 -fsanitize=address LDFLAGS := -lcriterion TESTBIN := /tmp/all_tests diff --git a/test_macro_magic.c b/test_macro_magic.c new file mode 100644 index 0000000..c3c7ef5 --- /dev/null +++ b/test_macro_magic.c @@ -0,0 +1,20 @@ +#include + +enum animal { + dog, + cat, +}; + +typedef struct args { + enum animal animal; +} args_t; + +#define ARGS_DEFAULT .animal=cat +#define ARGS(...) ((args_t){ ARGS_DEFAULT, __VA_ARGS__ }) + +Test(macro_magic, default_values) { + args_t a1 = ARGS(); + args_t a2 = ARGS(.animal=dog); + cr_assert_eq(a1.animal, cat); + cr_assert_eq(a2.animal, dog); +}