法律C或gcc中的错误 [英] Legal C or bug in gcc
问题描述
偶然我在一些Linux代码中遇到了这样的bug我今天要写的
。发生的一切都是我忘记了其他。然而
代码仍然编译并运行。简化示例如下。
#include< stdio.h>
main()
{
int a;
if(1 == 1)a = 1;
{
a = 2;
}
printf(" a =%d \ n",a);
}
运行时,它将打印a = 2。它应该编译还是GCC
解析器坏了?
B2003
By accident I came across a bug like this in some Linux code I''d
written today. All that had happened is I forgot the "else" yet the
code still compiled and ran. A simplified example is below.
#include <stdio.h>
main()
{
int a;
if (1 == 1) a = 1;
{
a = 2;
}
printf("a = %d\n",a);
}
When run it will print "a = 2". Should it compile at all or is GCCs
parser broken?
B2003
推荐答案
在文章< a2 ********************************** @ o77g2000hsf中。 googlegroups.com>,
Boltar< bo ******** @ yahoo.co.ukwrote:
In article <a2**********************************@o77g2000hsf. googlegroups.com>,
Boltar <bo********@yahoo.co.ukwrote:
>偶然的是,我在今天写的一些Linux代码中遇到了这样的bug。发生的一切都是我忘记了其他。然而
代码仍然编译并运行。下面是一个简单的例子。
#include< stdio.h>
main()
$
int a;
如果(1 == 1)a = 1;
{
a = 2;
}
printf(" a =%d \ n",a);
运行时会打印a = 2。它应该编译还是GCC
解析器坏了?
B2003
>By accident I came across a bug like this in some Linux code I''d
written today. All that had happened is I forgot the "else" yet the
code still compiled and ran. A simplified example is below.
#include <stdio.h>
main()
{
int a;
if (1 == 1) a = 1;
{
a = 2;
}
printf("a = %d\n",a);
}
When run it will print "a = 2". Should it compile at all or is GCCs
parser broken?
B2003
我可以重新发布我的我写了这个你好的世界程序,并且它编译并运行得很好;为什么"?;帖子。
Time for me to re-post my "I wrote this hello, world program and it
compiled and ran just fine; why?" post.
2月27日,09:44,凝视...... @ xmission.xmission.com(Kenny McCormack)
写道:
On 27 Feb, 09:44, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
时间让我重新发布我的我写了这个问候,世界计划和它
编译并运行只是精细;为什么"?;帖子。
Time for me to re-post my "I wrote this hello, world program and it
compiled and ran just fine; why?" post.
我应该知道比期待这个
组合理的回答更好。
无论如何,我只是意识到它将括号中的部分视为一个单独的b
块,这样你就可以保存更多的讽刺回复。
B2003
I should''ve known better than to expect a sensible answer from this
group.
Anyway , I just realised its treating the bracketed part as a seperate
block so you can save anymore sarcastic responses.
B2003
Boltar< bo ******** @ yahoo.co.ukwrites:
Boltar <bo********@yahoo.co.ukwrites:
偶然我来了在某些Linux代码中,这样的bug我会写一下今天写的
。发生的一切都是我忘记了其他。然而
代码仍然编译并运行。简化示例如下。
#include< stdio.h>
main()
{
int a;
if(1 == 1)a = 1;
{
a = 2;
}
printf(" a =%d \ n",a);
}
运行时,它将打印a = 2。它应该编译还是GCC
解析器坏了吗?
By accident I came across a bug like this in some Linux code I''d
written today. All that had happened is I forgot the "else" yet the
code still compiled and ran. A simplified example is below.
#include <stdio.h>
main()
{
int a;
if (1 == 1) a = 1;
{
a = 2;
}
printf("a = %d\n",a);
}
When run it will print "a = 2". Should it compile at all or is GCCs
parser broken?
完全合法。复合语句(包含其他
语句的大括号)只是另一个有效选项,其中一个语句需要
。
-
Ben。
It is entirely legal. A compound statement (braces containing other
statements) is just another valid option where a statement is
required.
--
Ben.
这篇关于法律C或gcc中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!