#include #include typedef unsigned char byte; typedef struct color_s{ byte red; byte green; byte blue; float alpha; } color; typedef struct color2_s{ byte red; byte green; byte blue; byte alpha; } color2; typedef union{ color2 c; int i; } color3; color * createColor(byte r, byte g, byte b, float a){ color * c = (color *)malloc(sizeof(color)); c->red = r; c->green = g; c->blue = b; c->alpha = a; return c; } int main(int argc, char * argv[]){ color c; color * c2 = createColor(100,200,50,1.0); c.red = 255; c.green = 127; c.blue = 0; c.alpha = 0.5; printf("red: %p, green: %p, blue: %p, alpha: %p\n", &c.red, &c.green, &c.blue, &c.alpha); printf("[%d, %d, %d, %f]\n", c.red, c.green, c.blue, c.alpha); color3 c3; c3.c.red = 255; c3.c.green = 127; c3.c.blue = 64; c3.c.alpha = 32; printf("[%d, %d, %d, %d], %x\n", c3.c.red, c3.c.green, c3.c.blue, c3.c.alpha, c3.i); c3.i = 0x0000ffff; printf("[%d, %d, %d, %d], %x\n", c3.c.red, c3.c.green, c3.c.blue, c3.c.alpha, c3.i); return 0; }