怀疑gcc4初始化者的bug [英] Bug in gcc4 initialisers suspected

查看:85
本文介绍了怀疑gcc4初始化者的bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


我想确认我怀疑gcc4 for MacOSX中的编译器

错误。下面的代码示例需要

,'v'的初始化程序将

vubytes []中的所有元素设置为零,如C99标准所指定的那样: />

""" 21如果括号括起来的

列表中的初始值设定项少于
$ b的元素或成员$ b聚合,[...]聚合的剩余部分应该隐含地初始化为与

具有静态存储持续时间的对象相同。""

(参考:ANSI + ISO + IEC + 8999-1999,6.7.8初始化,第127页)


但是,代码只能按预期工作在某些平台上:


系统cpu编译结果

------ --- -------- ----- -

SunOS-5.8 UltraSPARC-IIe gcc-2.95.3返回OK

FreeBSD-4.11 Pentium2 gcc-2.95.4返回OK

SunOS -5.8 UltraSPARC-IIi gcc-3.1.1返回OK

Darwin-7.9.0 PowerPC -G4 gcc-3.3返回OK

Linux-2.4.29 Celeron gcc-3.3.5返回OK

FreeBSD-5.4 Pentium4 gcc-3.4.2返回OK

Darwin-8.0.0 PowerPC-G4 gcc-4.0.0断言`vubytes [1] == 0''

Darwin-8.0.0 PowerPC-G5 gcc-4.0 .0断言`vubytes [1] == 0''


有趣的是,删除中级

级别''union u''会产生代码传递。


问题我正在寻求答案:

1.这是编译器错误还是显示未定义的行为?

2.这是gcc4特定的还是仅与PowerPC结合使用?


祝你好运,


Marcel
- _ _

_ | | _ | _ |

| _ | _ Marcel van Kervinck

| _ | ma*****@bitpit.net


----- -------------------------------------------------- ---------

#include< assert.h>


typedef struct {

union {

unsigned char bytes [2];

} u;

} vector_t;


int main(无效)

{

int i;

for(i = 0; i< 2; i ++){

vector_t v = {{{0,}}};

断言(vubytes [1] == 0);

vubytes [1] ++ ;

}

}

----------------------- -----------------------------------------

Dear all,

I would like to confirm my suspicion of a compiler
bug in gcc4 for MacOSX. The code example below expects
that the initializer of ''v'' sets all elements in
v.u.bytes[] to zero, as specified by the C99 standard:

"""21 If there are fewer initializers in a brace-enclosed
list than there are elements or members of an
aggregate, [...] the remainder of the aggregate shall
be initialized implicitly the same as objects that
have static storage duration."""
(ref: ANSI+ISO+IEC+8999-1999, 6.7.8 Initialization, p.127)

However, the code only works as expected on some platforms:

system cpu compiler result
------ --- -------- ------
SunOS-5.8 UltraSPARC-IIe gcc-2.95.3 returns OK
FreeBSD-4.11 Pentium2 gcc-2.95.4 returns OK
SunOS-5.8 UltraSPARC-IIi gcc-3.1.1 returns OK
Darwin-7.9.0 PowerPC-G4 gcc-3.3 returns OK
Linux-2.4.29 Celeron gcc-3.3.5 returns OK
FreeBSD-5.4 Pentium4 gcc-3.4.2 returns OK
Darwin-8.0.0 PowerPC-G4 gcc-4.0.0 failed assertion `v.u.bytes[1] == 0''
Darwin-8.0.0 PowerPC-G5 gcc-4.0.0 failed assertion `v.u.bytes[1] == 0''

Interestingly, removing the intermediate
level ''union u'' makes the code pass.

The questions I''m seeking an answer to:
1. Is this a compiler bug or a display of undefined behaviour?
2. Is this gcc4-specific or only in combination with PowerPC?

Best regards,

Marcel
-- _ _
_| |_|_|
|_ |_ Marcel van Kervinck
|_| ma*****@bitpit.net

----------------------------------------------------------------
#include <assert.h>

typedef struct {
union {
unsigned char bytes[2];
} u;
} vector_t;

int main(void)
{
int i;
for (i=0; i<2; i++) {
vector_t v = {{{0,}}};
assert(v.u.bytes[1] == 0);
v.u.bytes[1]++;
}
}
----------------------------------------------------------------

推荐答案

Marcel van Kervinck写道:
Marcel van Kervinck wrote:
亲爱的,

我想证实我怀疑编译器
Mac OSX的gcc4中的错误。下面的代码示例要求
初始化程序''v''将
vubytes []中的所有元素设置为零,如C99标准所规定:

" "" 21如果支架封闭的清单中的初始化程序少于
聚合的元素或成员,则聚合的其余部分应为
隐式初始化与具有静态存储持续时间的对象相同。""
(参考:ANSI + ISO + IEC + 8999-1999,6.7.8初始化,第127页)
系统cpu编译结果
------ --- ------- - ------
SunOS-5.8 UltraSPARC-IIe gcc-2.95.3返回OK
FreeBSD-4.11 Pentium2 gcc-2.95.4返回OK
SunOS-5.8 UltraSPARC-IIi gcc -3.1.1返回OK
Darwin-7.9.0 PowerPC-G4 gcc-3.3返回OK
Linux-2.4。 29 Celeron gcc-3.3.5返回OK
FreeBSD-5.4 Pentium4 gcc-3.4.2返回OK
Darwin-8.0.0 PowerPC-G4 gcc-4.0.0断言`vubytes [1] = = 0''
Darwin-8.0.0 PowerPC-G5 gcc-4.0.0断言`vubytes [1] == 0''

有趣的是,删除中间的
level''union u''使代码通过。

我正在寻求答案的问题:
1.这是编译器错误还是显示未定义的行为?
2.这是gcc4特定的还是仅与PowerPC结合使用?


问题是,如果没有告诉我们你如何调用gcc,我们无法分辨


您是否编译过 ; -std = c99 -pedantic"?

你检查过gcc.gnu.org/c99status.html吗?


除此之外,gnu.gcc。帮助可能是一个更好的地方。


干杯

Michael
致以最诚挚的问候,

Marcel - _ _
_ | | _ | _ |
| _ | _ Marcel van Kervinck
| _ | ma*****@bitpit.net

--------- -------------------------------------------------- -----
#include< assert.h>

typedef struct {
union {
unsigned char bytes [2];
} u;
} vector_t;

int main(void)
{
int i;
for(i = 0; i< 2; i ++) {
vector_t v = {{{0,}}};
断言(vubytes [1] == 0);
vubytes [1] ++;
}
}
----------------------------------------- -----------------------
Dear all,

I would like to confirm my suspicion of a compiler
bug in gcc4 for MacOSX. The code example below expects
that the initializer of ''v'' sets all elements in
v.u.bytes[] to zero, as specified by the C99 standard:

"""21 If there are fewer initializers in a brace-enclosed
list than there are elements or members of an
aggregate, [...] the remainder of the aggregate shall
be initialized implicitly the same as objects that
have static storage duration."""
(ref: ANSI+ISO+IEC+8999-1999, 6.7.8 Initialization, p.127)

However, the code only works as expected on some platforms:

system cpu compiler result
------ --- -------- ------
SunOS-5.8 UltraSPARC-IIe gcc-2.95.3 returns OK
FreeBSD-4.11 Pentium2 gcc-2.95.4 returns OK
SunOS-5.8 UltraSPARC-IIi gcc-3.1.1 returns OK
Darwin-7.9.0 PowerPC-G4 gcc-3.3 returns OK
Linux-2.4.29 Celeron gcc-3.3.5 returns OK
FreeBSD-5.4 Pentium4 gcc-3.4.2 returns OK
Darwin-8.0.0 PowerPC-G4 gcc-4.0.0 failed assertion `v.u.bytes[1] == 0''
Darwin-8.0.0 PowerPC-G5 gcc-4.0.0 failed assertion `v.u.bytes[1] == 0''

Interestingly, removing the intermediate
level ''union u'' makes the code pass.

The questions I''m seeking an answer to:
1. Is this a compiler bug or a display of undefined behaviour?
2. Is this gcc4-specific or only in combination with PowerPC?
The problem is that without your telling us how you invoke gcc,
we cannot tell.
Did you compile with "-std=c99 -pedantic"?
Did you check gcc.gnu.org/c99status.html?

Apart from that, gnu.gcc.help may be a better place to ask.

Cheers
Michael
Best regards,

Marcel
-- _ _
_| |_|_|
|_ |_ Marcel van Kervinck
|_| ma*****@bitpit.net

----------------------------------------------------------------
#include <assert.h>

typedef struct {
union {
unsigned char bytes[2];
} u;
} vector_t;

int main(void)
{
int i;
for (i=0; i<2; i++) {
vector_t v = {{{0,}}};
assert(v.u.bytes[1] == 0);
v.u.bytes[1]++;
}
}
----------------------------------------------------------------



-

电子邮箱:我的是/ at / gmx / dot / de地址。


--
E-Mail: Mine is an /at/ gmx /dot/ de address.


在comp.lang.c中Michael Mair< Mi ********** @无效。无效>写道:
In comp.lang.c Michael Mair <Mi**********@invalid.invalid> wrote:
Marcel van Kervinck写道:
Marcel van Kervinck wrote:
我想证实我对编译器的怀疑
错误在gcc4中为MacOSX。下面的代码示例要求
初始化程序''v''将
vubytes []中的所有元素设置为零,如C99标准所规定:
[snip]

Darwin-8.0.0 PowerPC-G4 gcc-4.0.0断言`vubytes [1] == 0''
Darwin-8.0.0 PowerPC-G5 gcc-4.0.0断言失败`vubytes [1] == 0''

有趣的是,删除中级
级别''union u''使代码通过。

问题我正在寻找答案:
1.这是编译器错误还是显示未定义的行为?
2.这是gcc4特定的还是仅与PowerPC结合使用?
问题在于,如果没有告诉我们你如何调用gcc,我们无法分辨。
你是否编译了-std = c99 -pedantic?
你检查了吗? gcc.gnu.org/c99status.html?
I would like to confirm my suspicion of a compiler
bug in gcc4 for MacOSX. The code example below expects
that the initializer of ''v'' sets all elements in
v.u.bytes[] to zero, as specified by the C99 standard: [snip]
Darwin-8.0.0 PowerPC-G4 gcc-4.0.0 failed assertion `v.u.bytes[1] == 0''
Darwin-8.0.0 PowerPC-G5 gcc-4.0.0 failed assertion `v.u.bytes[1] == 0''

Interestingly, removing the intermediate
level ''union u'' makes the code pass.

The questions I''m seeking an answer to:
1. Is this a compiler bug or a display of undefined behaviour?
2. Is this gcc4-specific or only in combination with PowerPC? The problem is that without your telling us how you invoke gcc,
we cannot tell.
Did you compile with "-std=c99 -pedantic"?
Did you check gcc.gnu.org/c99status.html?




我在代码中没有看到任何特定于C99的东西。


[snip]

#include< assert.h>

typedef struct {
union {
unsigned char bytes [2];
} u;
} vector_t;

int main(void)
{
int i;
for(i = 0; i< ; 2; i ++){
vector_t v = {{{0,}}};
断言(vubytes [1] == 0);
vubytes [1] ++;
}
}



I don''t see anything in the code which is C99 specific.

[snip]
#include <assert.h>

typedef struct {
union {
unsigned char bytes[2];
} u;
} vector_t;

int main(void)
{
int i;
for (i=0; i<2; i++) {
vector_t v = {{{0,}}};
assert(v.u.bytes[1] == 0);
v.u.bytes[1]++;
}
}




如果`assert''失败,那么它很可能是编译器错误。

但我不是这里的权威(从clc写)。


-

Stan Tobias

mailx`echo si *** @FamOuS.BedBuG.pAlS.INVA LID | sed s / [[:upper:]] // g`



If the `assert'' fails, then it''s most probably a compiler bug.
But I am not an authority here (writing from clc).

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`


S.Tobias写道:
S.Tobias wrote:
在comp.lang.c Michael Mair <弥********** @ invalid.invalid>写道:
In comp.lang.c Michael Mair <Mi**********@invalid.invalid> wrote:
Marcel van Kervinck写道:
Marcel van Kervinck wrote:
我想证实我怀疑编译器<对于MacOSX,gcc4中的错误。下面的代码示例要求
初始化程序''v''将
vubytes []中的所有元素设置为零,如C99标准所规定:
[snip]

Darwin-8.0.0 PowerPC-G4 gcc-4.0.0断言`vubytes [1] == 0''
Darwin-8.0.0 PowerPC-G5 gcc-4.0.0断言失败`vubytes [1] == 0''

有趣的是,删除中级
级别''union u''使代码通过。

问题我正在寻求答案:
1。这是编译器错误还是显示未定义的行为?
2。这是特定于gcc4还是仅与PowerPC结合使用?
I would like to confirm my suspicion of a compiler
bug in gcc4 for MacOSX. The code example below expects
that the initializer of ''v'' sets all elements in
v.u.bytes[] to zero, as specified by the C99 standard:
[snip]

Darwin-8.0.0 PowerPC-G4 gcc-4.0.0 failed assertion `v.u.bytes[1] == 0''
Darwin-8.0.0 PowerPC-G5 gcc-4.0.0 failed assertion `v.u.bytes[1] == 0''

Interestingly, removing the intermediate
level ''union u'' makes the code pass.

The questions I''m seeking an answer to:
1. Is this a compiler bug or a display of undefined behaviour?
2. Is this gcc4-specific or only in combination with PowerPC?
问题是如果没有告诉我们你如何调用gcc,我们无法分辨。
你用-std = c99 -pedantic编译?
你检查过gcc.gnu.org/c99status.html吗?
The problem is that without your telling us how you invoke gcc,
we cannot tell.
Did you compile with "-std=c99 -pedantic"?
Did you check gcc.gnu.org/c99status.html?



我什么也看不见特定于C99的代码。


I don''t see anything in the code which is C99 specific.




C89要求main()中的return语句或其他

方式未运行到最后of main()(例如exit()或

abort())。 C99允许你从main()的末尾掉下来......


所以,给定一个return 0;,代码也可以用
编译
" -std = c89 -pedantic" (或等同于-ansi -pedantic


干杯

Michael
[snip]

#include < assert.h>

typedef struct {
union {
unsigned char bytes [2];
} u;
} vector_t;

int main(void)
{
int i;
for(i = 0; i< 2; i ++){
vector_t v = {{{ 0,}}};
断言(vubytes [1] == 0);
vubytes [1] ++;
}
}



C89 requires either a return statement in main() or another
way of not running into the end of main() (e.g. exit() or
abort()). C99 allows you to fall off the end of main()...

So, given a "return 0;", the code could also be compiled with
"-std=c89 -pedantic" (or equivalently with "-ansi -pedantic"

Cheers
Michael
[snip]

#include <assert.h>

typedef struct {
union {
unsigned char bytes[2];
} u;
} vector_t;

int main(void)
{
int i;
for (i=0; i<2; i++) {
vector_t v = {{{0,}}};
assert(v.u.bytes[1] == 0);
v.u.bytes[1]++;
}
}



如果`assert''失败,那么它很可能是编译器错误。
但我不是这里的权威(从clc写)。


If the `assert'' fails, then it''s most probably a compiler bug.
But I am not an authority here (writing from clc).



-

电子邮件:我的是/ at / gmx / dot / de地址。


--
E-Mail: Mine is an /at/ gmx /dot/ de address.


这篇关于怀疑gcc4初始化者的bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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