This is the mail archive of the gcc@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]

problem when returning a structure containing arrays.


Hi, 

I compiled the follwing code with gcc -shared buglib.c -o buglib.dll:


>>> buglib.h is:

   struct T
   {
     double x[256];
     double y[256];
     int   i;
   };
   struct T fun(int a);

>>> buglib.c is
   
   #include "buglib.h"

   struct T fun(int a)
   {
     struct T retval;
     int i;
     for (i=0; i<256;++i)
     {
	     retval.x[i]=(double)i;
	     retval.y[i]=(double)i;  
     }
     return retval;
   }

If I linkt this lib to

>>> main.c 

    #include <stdio.h>
    #include "buglib.h"


    int main()
    {
	struct T x = fun(1);
	int i;
	for (i=0; i<10; ++i)
		printf("%d %d\n", x.x[i],  x.y[i]);
    }

Now the output is totally wrong !
I tried it with the cygwin port gcc 3.4.4 and with
gcc 3.3.1 on Suse Linux.

Any hints ?

Greetings, Uwe


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