我看过这个链接
我enums在客户端提供的库头文件(我无法更改)中以下列方式定义了一系列:
枚举也很稀疏.
typedef enum
{
ERROR_NONE=59,
ERROR_A=65,
ERROR_B=67
}
Run Code Online (Sandbox Code Playgroud)
我想在我的函数中打印这些值,例如我想打印ERROR_NONE而不是59.有没有更好的方法来使用switch case或if else构造来完成这项工作?例
int Status=0;
/* some processing in library where Status changes to 59 */
printf("Status = %d\n",Status); /* want to print ERROR_NONE instead of 59 */
Run Code Online (Sandbox Code Playgroud)
常见问题 11.17。使用xstr()宏。你可能应该使用它:
#define str(x) #x
#define xstr(x) str(x)
printf("%s\n", xstr(ERROR_A));
Run Code Online (Sandbox Code Playgroud)