I am trying to generate overloaded functions using _Generic macro in C11, and I have stopped on zero arguments function support, e.g:
#define msg(_1) _Generic((_1), char*: msg_string, default: msg_none)(_1)
char* msg_none(void){
return moo_string("Have a nice day!");
}
char* msg_string(char* message){
int msglen = strlen(message);
char* result = malloc(msglen + 3);
sprintf(result, "<%s>\n", message);
return result;
}
For now compiling and running:
printf("%s",msg("hello!"));
goes without any problem, but:
printf("%s",msg());
throws error:
main.c:7:17: error: expected expression
printf("%s",msg());
I am using:
clang --version
clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
GCC throws:
main.c:7:5: warning: implicit declaration of function ‘_Generic’
so I understand _Generic is not supported this version of gcc:
gcc --version
gcc (Gentoo 4.8.3 p1.1, pie-0.5.9) 4.8.3
Is my problem even solvable or I just overestimate capabilities of _Generic, or I just need to upgrade my compilers to use this options properly ?