Created
March 26, 2014 10:15
-
-
Save memononen/9780262 to your computer and use it in GitHub Desktop.
va args for uints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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