gpt4 book ai didi

C 中的编译错误只是因为缩进?

转载 作者:行者123 更新时间:2023-12-05 08:14:48 24 4
gpt4 key购买 nike

我创建了一个简单的 C 程序,它根据用户输入 4 = 4x4、5 = 5x5 等创建一个正方形。

我的程序没有像下面那样正确编译,一段时间后我能够通过从第二个 printf 中删除缩进来修复它。

这正常吗?或者这只是我的 IDE?我是 C 的新手,但总的来说我从未见过缩进会影响代码功能,所以我只是想多了解一点。

谢谢!

int main(void)
{

int height;

do
{

height = get_int("Height: ");

}
while (height>9 || height<1);


for (int i = 0; i < height; i++)

{
for (int j = 0; j < height; j++)

printf ("#");
printf ("\n");


}

}

错误:

clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow    mario.c  -lcrypt -lcs50 -lm -o mariomario.c:24:6: error: misleading indentation; statement is not part of the previous 'for' [-Werror,-Wmisleading-indentation]     printf ("\n");     ^mario.c:21:4: note: previous statement is here   for (int j = 0; j : mario] Error 1

最佳答案

关于误导性缩进的警告不是标准 C 的一部分。它是 extension provided by Clang并由 -Wall 启用您使用的开关(直接或通过 IDE 中的设置)。使用 -Werror 将警告提升为错误。

这是最近添加到 Clang 中的(它在 Clang 12 中,但不在 Apple 的 Clang 11 中),并且使用 -Wall 是激进的,因此它可能在未来包含新的警告功能。

关于C 中的编译错误只是因为缩进?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66198475/

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