Mercurial > hg > Members > ikki > CbC_log
changeset 2:3a1b47368e51
add unionTest
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Mar 2021 18:45:11 +0900 |
parents | 81cf42d17859 |
children | 221b3052e3b8 |
files | unionTest/unionTest.c |
diffstat | 1 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unionTest/unionTest.c Fri Mar 12 18:45:11 2021 +0900 @@ -0,0 +1,26 @@ +#include <stdio.h> + +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; + //printf("%d\n", unionTest->hoge.foo); + printf("%d\n", ((hoge*)unionTest)->foo); + return 0; +} + +