problem when returning a structure containing arrays.

2006-08-30 Thread Uwe Schmitt

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 
#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



Re: problem when returning a structure containing arrays

2006-08-30 Thread Uwe Schmitt

Sorry, 
I made a mistake with the printf()-formatting-
charcters.

Greetings, Uwe