Skip to content

Instantly share code, notes, and snippets.

@cfr
Last active December 20, 2015 01:59
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 cfr/6053230 to your computer and use it in GitHub Desktop.
Save cfr/6053230 to your computer and use it in GitHub Desktop.
C11 _Generic print
#define printf_dec_format(x) _Generic((x), \
char: "%c", \
signed char: "%hhd", \
unsigned char: "%hhu", \
signed short: "%hd", \
unsigned short: "%hu", \
signed int: "%d", \
unsigned int: "%u", \
long int: "%ld", \
unsigned long int: "%lu", \
long long int: "%lld", \
unsigned long long int: "%llu", \
float: "%f", \
double: "%f", \
long double: "%Lf", \
char *: "%s", \
void *: "%p")
#define print(x) printf(printf_dec_format(x), x)
#define printnl(x) printf(printf_dec_format(x), x), printf("\n");
@cfr
Copy link
Author

cfr commented Jul 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment