Skip to content

Instantly share code, notes, and snippets.

@mbohun
Created August 31, 2012 03:50
Show Gist options
  • Save mbohun/3548880 to your computer and use it in GitHub Desktop.
Save mbohun/3548880 to your computer and use it in GitHub Desktop.
float4 type (union)
#include <stdio.h>
struct float4 {
union {
struct { float r, g, b, a; };
struct { float x, y, z, w; };
float at[4];
};
};
inline void float4_copy(struct float4 *const dst,
struct float4 const *const src) {
}
inline void float4_zero(struct float4 *const val) {
val->x = val->y = val->z = val->w = 0.0;
}
inline void float4_dot() {
}
inline void float4_norm() {
}
int main(int argc, char* argv[]) {
struct float4 col;
float4_set(&col, 0.666, 0.666, 0.666, 0.666);
printf("%f %f %f %f\n", col.r, col.g, col.b, col.a);
float4_zero(&col);
col.a = 0.666;
col.at[2] = 1.112;
float* p = &col.r;
p[1] = 0.4242;
printf("%f %f %f %f\n", col.r, col.g, col.b, col.a);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment