This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/37371] New: wrong initialisation of an array of ptrs
- From: "skylendar at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Sep 2008 14:50:02 -0000
- Subject: [Bug c/37371] New: wrong initialisation of an array of ptrs
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
First of all, thanx to all the gcc team for their fantastic job.
gcc: 4.3.2 bootstraped with CFLAGS=-O2 -pipe -march=athlon -fomit-frame-pointer
Target: linux 2.6.25 on mandriva 2008.0
Problem: the following code works fine with low optimization -O0, -O1,
but gives fancy results with -O2, -O3. No problem with compilation.
The fill function fills up and array of char * with char* provided as
arguments.
The arguments are 0L terminated.
The example program should produce:
a
b
c
Thanx beforehand for your attention.
...
#include <stdio.h>
void fill(char *t[], char *c, ...)
{
char **ptr = &c;
while(*ptr)
*t++ = *ptr++;
}
int main()
{
int i;
char *abc[3];
fill(abc, "a", "b", "c", 0L);
for(i = 0; i < 3; i++)
printf("%s\n", abc[i]);
}
--
Summary: wrong initialisation of an array of ptrs
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: skylendar at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37371