GNU89,混合声明和循环初始声明 [英] GNU89, mixed declarations and loop initial declarations

查看:269
本文介绍了GNU89,混合声明和循环初始声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC和ICC的缺省C方言GNU89。 GNU89允许混合声明例如

The default C dialect for GCC and ICC is GNU89. GNU89 allows mixed declarations e.g.

int i;
i = 0;
int j;

我推测(错误地)从多个其他职位上的SO如 C:对环INT初始宣布,那这意味着我可以做

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

与GNU89但是当我这样做,我得到

with GNU89 but when I do this I get

error: 'for' loop initial declarations are only allowed in C99 mode

显然,混合声明和循环初始声明是不一样的东西(即一不意味着其他)。

Apparently, mixed declarations and loop initial declarations are not the same thing (i.e. one does not imply the other).

如果我只能有一个,我宁愿有循环初始声明。当然,我可以只使用GNU99但这不是问题的关键。默认值是GNU89而且它已经打破一些规则,C89(这也让BCPL / C ++风格的注释)。有没有为什么混合声明允许的,但一些基本的理由不循环初始声明?

If I could only have one I would rather have loop initial declarations. Of course, I could just use GNU99 but that's not the point. The default is GNU89 and it already breaks some C89 rules (it also allows BCPL/C++ style comments). Is there some fundamental reason why mixed declarations are allowed but not loop initial declarations?

推荐答案

混合宣言和声明,preDATE C89在其他语言(例如,大陵五68),是少数C89编译器(不MSCV)之间的共同推广。

Mixed declarations and statements predate C89 in other languages (e.g., Algol 68) and was a common extension among a few C89 compilers (not MSCV).

在另一方面一个声明计数器变量声明排在C到C ++ 98据我所知,没有C89编译器发现它足够有用的将其添加为一个C89扩展。

Counter variable declaration in a for statement on the other hand came in C through C++98 and to my knowledge no C89 compiler found it useful enough to add it as a C89 extension.

这篇关于GNU89,混合声明和循环初始声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆