Skip to content

Instantly share code, notes, and snippets.

@memononen
Created March 26, 2014 10:15
Show Gist options
  • Save memononen/9780262 to your computer and use it in GitHub Desktop.
Save memononen/9780262 to your computer and use it in GitHub Desktop.
va args for uints
#define foo(...) foo_(123, ##__VA_ARGS__, 0)
void foo_(int dummy, ...)
{
unsigned int v;
va_list list;
printf("foo ");
va_start(list, dummy);
for (v = va_arg(list, unsigned int); v != 0; v = va_arg(list, unsigned int))
printf("%d ", v);
va_end(list);
printf("\n");
}
#define foo2(...) foo2_((unsigned int[]){__VA_ARGS__}, (sizeof((unsigned int[]){__VA_ARGS__})/sizeof(int)))
void foo2_(unsigned int* v, int nv)
{
int i;
printf("foo2 ");
for (i = 0; i < nv; i++)
printf("%d ", v[i]);
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment