这是我想要做的:
typedef enum { ONE, TWO, THREE } Numbers;
Run Code Online (Sandbox Code Playgroud)
我正在尝试编写一个函数来执行类似于以下的切换案例:
char num_str[10];
int process_numbers_str(Numbers num) {
switch(num) {
case ONE:
case TWO:
case THREE:
{
strcpy(num_str, num); //some way to get the symbolic constant name in here?
} break;
default:
return 0; //no match
return 1;
}
Run Code Online (Sandbox Code Playgroud)
而不是在每种情况下定义,有没有办法使用枚举变量设置它,就像我在上面尝试做的那样?
调试宏可能需要很长时间.我们最好避免使用它们,除非在非常罕见的情况下,常量,函数和模板都不能达到我们想要的效果.
什么是罕见的情况?