diff --git a/21st_century_c/Makefile b/21st_century_c/Makefile index 490a45d..1087630 100644 --- a/21st_century_c/Makefile +++ b/21st_century_c/Makefile @@ -1,4 +1,4 @@ -CFLAGS = --std=c11 -Wall -O3 +CFLAGS = -Wall -O3 --std=c11 boxes : boxes.c @@ -10,6 +10,9 @@ show_tree : process_dir.h process_dir.c show_tree.c simple_cplx : cplx.h complex.c simple_cplx.c $(CC) `pkg-config --cflags --libs gsl` $(CFLAGS) complex.c $@.c -o $@ +seamlessone : seamlessone.c + $(CC) $(CFLAGS) -fms-extensions -Wno-microsoft $@.c -o $@ + .PHONY : all all : boxes show_tree simple_cplx @@ -22,4 +25,5 @@ clean : rm -f boxes rm -f show_tree rm -f simple_cplx + rm -f seamlessone rm -rf *.dSYM diff --git a/21st_century_c/seamlessone.c b/21st_century_c/seamlessone.c new file mode 100644 index 0000000..2845816 --- /dev/null +++ b/21st_century_c/seamlessone.c @@ -0,0 +1,32 @@ +#include +#include + + + +typedef struct point { + double x, y; +} point; + + +/* +Nested anonymous struct declaration compiles with MS extensions only. +So you have to use -fms-extensions flag with gcc / clang. +C11 standard allows no typedef in the nested anonymous declaration :( +*/ +typedef struct { + struct point; + double z; +} threepoint; + + +double threelength(threepoint p) { + return sqrt(p.x * p.x + p.y * p.y + p.z * p.z); +} + + +int main () { + + threepoint p = {.x = 3, .y = 0, .z = 4}; + printf("p is %g units from the origin\n", threelength(p)); + +}