C
Chris
This is what I want to do, I have enum and I want to turn it into a
string using the number I've assigned to and concatenting a string to
the end of it or displaying some error string for invalid enums.
typedef enum
{
Enabled = 1,
Disabled = 2
} State;
#define State_String(x) (\
(x == Enabled) ? #x":Enabled" : \
(x == Disabled) ? #x"
isabled" : \
#x":Unknown")
int main()
{
int i;
i = Enabled;
printf("State: %s", State_String(i));
i = Disabled;
printf("State: %s", State_String(i));
i = Disabled + 1;
printf("State: %s", State_String(i));
return 0;
}
I want the output to look like
1:Enabled
2
isabled
3:Unknown
But the output is
i:Enabled
i
isabled
i:Unknown
Anybody know how I can do this in a macro?
Thanks,
Cristov
string using the number I've assigned to and concatenting a string to
the end of it or displaying some error string for invalid enums.
typedef enum
{
Enabled = 1,
Disabled = 2
} State;
#define State_String(x) (\
(x == Enabled) ? #x":Enabled" : \
(x == Disabled) ? #x"
#x":Unknown")
int main()
{
int i;
i = Enabled;
printf("State: %s", State_String(i));
i = Disabled;
printf("State: %s", State_String(i));
i = Disabled + 1;
printf("State: %s", State_String(i));
return 0;
}
I want the output to look like
1:Enabled
2
3:Unknown
But the output is
i:Enabled
i
i:Unknown
Anybody know how I can do this in a macro?
Thanks,
Cristov