Last active
December 20, 2015 01:59
-
-
Save cfr/6053230 to your computer and use it in GitHub Desktop.
C11 _Generic print
This file contains 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 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: http://www.robertgamble.net/2012/01/c11-generic-selections.html