Skip to content

Instantly share code, notes, and snippets.

@robbiev
Created July 5, 2020 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbiev/3049753205198bc9960566262b4dd03d to your computer and use it in GitHub Desktop.
Save robbiev/3049753205198bc9960566262b4dd03d to your computer and use it in GitHub Desktop.
#include <stdio.h>
struct vec4_a {
union { float x, r; } a;
union { float y, g; } b;
union { float z, b; } c;
union { float w, a; } d;
};
union vec4_b {
struct {
float x, y, z, w;
} axis;
struct {
float r, g, b, a;
} color;
float data[4];
};
struct vec4_c {
union {
struct {
float x, y, z, w;
} axis_;
struct {
float r, g, b, a;
} color_;
} vec3;
};
int main(int argc, char *argv[]) {
struct vec4_a a = {{1}, {2}, {3}, {4}};
union vec4_b b = {{1, 2, 3, 4}};
struct vec4_c c = {{{1, 2, 3, 4}}};
printf("%zu\n", sizeof (struct vec4_a));
printf("%zu\n", sizeof (union vec4_b));
printf("%zu\n", sizeof (struct vec4_c));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment