case后用常量代替int值为什么会报错?

#include <stdio.h>
int red = 0;
int yellow=1;
int green=2;

int main(int argc,char const *argv[])
{
    int color=-1;
    char *output=NULL;
    
    scanf("%d",&color);
    switch(color)
    {
        case red: output="red";break;
        case yellow: output="yellow";break;
        case green: output="green";break;
        default: output="unknown";
    }
    
    printf("%s\n",output);
    
    
    return 0;
}

这段代码在case处会报错[Error] case label does not reduce to an integer constant,但是red,yellow,green的值已经在之前定义为常量了,为什么会报错呢,求教。

定义#define 就行

#include <stdio.h>
#define red 0
#define yellow 1
#define green 2
int main(int argc,char const *argv[])
{
    int color=-1;
    char *output=NULL;
    scanf("%d",&color);
    switch(color)
    {
        case red: output="red";break;
        case yellow: output="yellow";break;
        case green: output="green";break;
        default: output="unknown";
    }
    printf("%s\n",output);
    
    return 0;
}
 
 

red yellow green定义为变量,值可能改变,比如都改变为1。就会导致case产生错误。