When trying to implement a _Generic call that has both type bool and a struct, the struct is somehow caught in the bool case and an error is received.
Error(s):
source_file.c:27:14: error: used type 'struct sockaddr' where arithmetic or pointer type is required
printf("%s", log_param_encode(tempS));
^ ~~~~~
source_file.c:6:54: note: expanded from macro 'log_param_encode'
bool: (x ? "true" : "false"), \
if i change the bool case to include only a string such as "true", it works fine and i receive the "sockaddr" in the printf output.
the code:
#include <stdio.h>
#include <stdbool.h>
#include <sys/socket.h>
#define log_param_encode(x) _Generic((x), \
bool: (x ? "true" : "false"), \
struct sockaddr: "sockaddr", \
default: x)
int main(void)
{
struct sockaddr tempS;
printf("%s", log_param_encode(tempS));
return 0;
}
How is the _Generic expansion happening? why is it trying to use X in a case it isn't for?