gpt4 book ai didi

c - 没有标签的 switch 语句代码

转载 作者:太空宇宙 更新时间:2023-11-04 03:39:25 24 4
gpt4 key购买 nike

<分区>

为什么 ANSI C 允许在 switch 语句中的任何 case 标签之前使用无关代码?

#include <stdio.h>

int main(void) {
const int foo = 1;

switch (foo) {
printf("wut\n"); /* no label, doesn't output */
case 1:
printf("1\n");
break;
default:
printf("other\n");
break;
}

return 0;
}

编译为

$ gcc -pedantic -Wall -Werror -Wextra -ansi test.c

它在没有警告的情况下编译并且执行良好 - 没有“wut”

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com