view unionTest/unionTest.c @ 2:3a1b47368e51

add unionTest
author ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
date Fri, 12 Mar 2021 18:45:11 +0900
parents
children
line wrap: on
line source

#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;
}