gpt4 book ai didi

C- For 循环 gcc 中的 int 第一个声明

转载 作者:行者123 更新时间:2023-11-30 19:55:29 25 4
gpt4 key购买 nike

为什么会这样C代码无法用 gcc 编译?

for(int j=0; j<n; j++){
//some code here
}

我知道有一个解决方案,其中包括声明 jFor环形。但是,gcc中有任何选项吗?在C中做到这一点程序?

最佳答案

C99 及后者允许此功能。在 C99 模式 -std=C99 下编译代码。

C11:6.8.5.3 for 语句:

1 The statement

for ( clause-1 ; expression-2 ; expression-3 ) statement

behaves as follows: The expression expression-2 is the controlling expression that is evaluated before each execution of the loop body. The expression expression-3 is evaluated as a void expression after each execution of the loop body. If clause-1 is a declaration1, the scope of any identifiers it declares is the remainder of the declaration and the entire loop, including the other two expressions; it is reached in the order of execution before the first evaluation of the controlling expression. If clause-1 is an expression, it is evaluated as a void expression before the first evaluation of the controlling expression.158)

<小时/>

1.重点是我的。

关于C- For 循环 gcc 中的 int 第一个声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20887018/

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