Skip to content

Instantly share code, notes, and snippets.

@computermouth
Last active December 21, 2016 06:09
Show Gist options
  • Save computermouth/7a128e9a4876af6160573220cc837d2b to your computer and use it in GitHub Desktop.
Save computermouth/7a128e9a4876af6160573220cc837d2b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define NP_VX(verts) short x[verts]
#define NP_VY(verts) short y[verts]
#define NP_AX(xcoords...) = {xcoords};
#define NP_AY(ycoords...) = {ycoords};
#define NP_CO(vals...) short color[4] = {vals};
#define NP_SH(np_name, np_vx, np_vy, np_ax, np_ay, np_co) \
void np_name(){ \
np_vx \
np_ax \
np_vy \
np_ay \
np_co \
printf("x[1]+y[1]+color[1]: %d\n", (x[1]+y[1]+color[1])); \
}
NP_SH(
test_shape_1,
NP_VX(3),
NP_VY(3),
NP_AX(1, 2, 3),
NP_AY(4, 5, 6),
NP_CO(123, 234, 45, 12)
);
NP_SH(
test_shape_2,
NP_VX(5),
NP_VY(5),
NP_AX(111, 211, 311, 144, 345),
NP_AY(411, 511, 611, 123, 999),
NP_CO(123, 234, 45, 12)
);
/*
`gcc -E main.c` Expands the macro and usage to one-liners of:
void test_shape_1(){
short x[3] = {1, 2, 3};
short y[3] = {4, 5, 6};
short color[4] = {123, 234, 45, 12};
printf("x[1]+y[1]+color[1]: %d\n", (x[1]+y[1]+color[1]));
}
void test_shape_2(){
short x[5] = {111, 211, 311, 144, 345};
short y[5] = {411, 511, 611, 123, 999};
short color[4] = {123, 234, 45, 12};
printf("x[1]+y[1]+color[1]: %d\n", (x[1]+y[1]+color[1]));
}
*/
int main(){
test_shape_1();
test_shape_2();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment