# HG changeset patch # User ichikitakahiro # Date 1615544475 -32400 # Node ID 221b3052e3b84a5f483209c727b43b5feea8b8e2 # Parent 3a1b47368e51ee67f8ca2ccb9b19d6880d01ff41 add c_example diff -r 3a1b47368e51 -r 221b3052e3b8 c_example/macro.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c_example/macro.c Fri Mar 12 19:21:15 2021 +0900 @@ -0,0 +1,33 @@ +#include + +#define HOGE ("hoge") +#define ADD(a, b) (a+b) +#define FALSE (0) +#define TRUE (1) + +#define FOO(a, b) (printf("%d\n",a->b.foo)) +//% $CBC_COMPILER -E c_example/macro.c | less で見比べてみよう。 +//macroとしてFOOを定義している。コンパイル直前で置換される、 + +typedef struct hoge { + int foo; + char* bar; +} hoge; + +typedef struct hoge2 { + int foo; + char* bar; +} hoge2; + +union UNION{ + struct hoge hoge; + struct hoge2 hoge2; +}; + +int main(){ + hoge hu = {11, "hello"}; + union UNION *unionTest = (union UNION*) &hu; + FOO(unionTest, hoge); + puts(HOGE); + return FALSE; +}