This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/37371] New: wrong initialisation of an array of ptrs


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]