-- forwarded message -- Path: news.xs4all.nl!newsspool.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Sender: Marcel van Kervinck <[EMAIL PROTECTED]> From: Marcel van Kervinck <[EMAIL PROTECTED]> Subject: Bug in gcc4 initialisers suspected Newsgroups: comp.std.c,comp.lang.c Cc: gcc-bugs@gcc.gnu.org Organization: bitpit Summary: Keywords: User-Agent: tin/pre-1.4-980105 (UNIX) (Linux/2.4.29 (i686)) Date: 17 May 2005 15:37:00 GMT Lines: 61 Message-ID: <[EMAIL PROTECTED]> NNTP-Posting-Host: 194.109.162.75 X-Trace: 1116344220 news.xs4all.nl 64594 [::ffff:194.109.162.75]:60968 X-Complaints-To: [EMAIL PROTECTED] Xref: news.xs4all.nl comp.std.c:65499 comp.lang.c:681223
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 |_| [EMAIL PROTECTED] ---------------------------------------------------------------- #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]++; } } ---------------------------------------------------------------- -- end of forwarded message --