相关疑难解决方法(0)

clang enum溢出

使用-Wall -pedantic

#include <limits.h>
#include <stdio.h>

int main(void)
{
    enum x {
        a,
        max = INT_MAX,
        out_1
    };
    enum y {
        b,
        out_2 = INT_MAX + 1
    };


    printf("%d %d\n", out_1, out_2);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

铿锵回归

demo.c:9:3: warning: overflow in enumeration value
                out_1
                ^
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,编译器没有警告out_2溢出,他的值在编译时是未知的?

c enums overflow

5
推荐指数
1
解决办法
963
查看次数

标签 统计

c ×1

enums ×1

overflow ×1