可能重复: Why was mixing declarations and code forbidden up until C99?
与此警告相关的问题有几个:ISO C90 forbids mixed declarations and code,但它们并没有解决为什么C90标准中首先存在这样的问题。
所以-为什么要这么做?
发布于 2013-01-31 18:17:17
我所知道的最大原因是它简化了语言、语法和解析器。
使用前面的声明,代码块必须如下所示
{
<declarations>
<stmts>
}因此,<stmts>的定义被简化了,因为它不需要涉及声明。这反过来简化了解析器,因为它只需要在块开始时从声明中消除语句的歧义。
实际上,代码块的这个特定定义是在标准中编码的:
3.6.2 Compound statement, or block
Syntax
compound-statement:
{ declaration-list<opt> statement-list<opt> }
declaration-list:
declaration
declaration-list declaration
statement-list:
statement
statement-list statementhttps://stackoverflow.com/questions/14632395
复制相似问题