我想知道为什么gcc在枚举的比较/赋值时表现出不同。考虑以下示例:
void func(void) {
enum {foo, bar} e1 = foo;
enum {baz, qux} e2 = qux;
e1 = e2; /* Assignment */
if (e1 == e2) /* Comparison */
/* Do something */
}
当我编译这段代码时
gcc main.c -o bin -std=c11 -Wall -Wextra -Wpedantic
对于枚举比较,我会收到警告,但对作业却不会:
warning: comparison between ‘enum <anonymous>’ and ‘enum <anonymous>’ [-Wenum-compare]
if (e1 == e2)
^~