jweinst1
6/26/2017 - 1:23 AM

casting example in c

casting example in c

#include <stdio.h>

typedef unsigned char XenonType;



typedef struct {
    XenonType type;
} XenonObject;

typedef struct {
    XenonType type;
    int none;
} XenonNone;

int main()
{
    XenonNone g = {4, 0};
    XenonNone* d = &g;
    XenonObject * f = (XenonObject*)d;
    printf("the type is %d\n", f->type);
    //the type is 4
    XenonNone*a = (XenonNone*)f;
    printf("the non is %d\n", a->none);
    return 0;
}