I wanted _Generic to work for the char data type:
#include <stdio.h>
#define test(x) _Generic((x), \
char: 0, \
int: 1, \
double: 3, \
default: 4 \
)
int main()
{
printf("%c\n", test('c')); // Result was ☺ character so I switched to %d
printf("%d\n", test('c')); // 1, which I would have received if 'c' was an int but 'c' is a char
return 0;
}
By the way I am aware that chars are technically ints. I just want to know if there is any way to fix this so it prints 0 instead.
Here is a link if you need information about _Generic: http://www.robertgamble.net/2012/01/c11-generic-selections.html