#include <stdio.h>
typedef struct {
enum { is_int, is_float, is_char, is_pointer } type;
union {
int i;
float f;
char c;
void *p;
} value;
} Tipo;
int main(void) {
int x = 10;
float y = 5.5f;
char c = 'h';
char a[] = "teste";
Tipo var1 = { .type = is_int, .value.i = x };
Tipo var2 = { .type = is_float, .value.f = y };
Tipo var3 = { .type = is_char, .value.c = c };
Tipo var4 = { .type = is_pointer, .value.p = a };
printf("%s\n", (char *)var4.
value.
p); printf("%zd\n", sizeof(var2
)); printf("%zd\n", sizeof(var3
)); }
//http://pt.stackoverflow.com/q/180783/101
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp0eXBlZGVmIHN0cnVjdCB7CiAgICBlbnVtIHsgaXNfaW50LCBpc19mbG9hdCwgaXNfY2hhciwgaXNfcG9pbnRlciB9IHR5cGU7CiAgICB1bmlvbiB7CiAgICAgICAgaW50IGk7CiAgICAgICAgZmxvYXQgZjsKICAgICAgICBjaGFyIGM7CiAgICAgICAgdm9pZCAqcDsKICAgIH0gdmFsdWU7Cn0gVGlwbzsKCmludCBtYWluKHZvaWQpIHsKCWludCB4ID0gMTA7CglmbG9hdCB5ID0gNS41ZjsKCWNoYXIgYyA9ICdoJzsKCWNoYXIgYVtdID0gInRlc3RlIjsKCVRpcG8gdmFyMSA9IHsgLnR5cGUgPSBpc19pbnQsIC52YWx1ZS5pID0geCB9OwoJVGlwbyB2YXIyID0geyAudHlwZSA9IGlzX2Zsb2F0LCAudmFsdWUuZiA9IHkgfTsKCVRpcG8gdmFyMyA9IHsgLnR5cGUgPSBpc19jaGFyLCAudmFsdWUuYyA9IGMgfTsKCVRpcG8gdmFyNCA9IHsgLnR5cGUgPSBpc19wb2ludGVyLCAudmFsdWUucCA9IGEgfTsKCXByaW50ZigiJWRcbiIsIHZhcjEudmFsdWUuaSk7CglwcmludGYoIiVmXG4iLCB2YXIyLnZhbHVlLmYpOwoJcHJpbnRmKCIlY1xuIiwgdmFyMy52YWx1ZS5jKTsKCXByaW50ZigiJXNcbiI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