Subject: Re: cygwin gcc and arrays -- Possible bug???
From: Cynthia Randles <[email-masked]>
To: [email-masked]
Date: Wed, 28 Aug 2002 16:08:51 -0400

Dear Igor:

Igor Pechtchanski wrote:
> 
> Which version of gcc are you using?  

Well, since I just downloaded cygwin last week, I assume I have the
latest version of gcc.  I think it is gcc-2.95.

Which libraries are you linking in?
#include <stdio.h>
#include <math.h>

> How are you allocating/declaring rad_array and vol_array?  
#define NUMBINS (51 - 1)

 float rad_array[NUMBINS], vol_array[NUMBINS];

>Is this a C or  C++ program?  
C

Please also check your loop limits - are you sure you wanted
> a '<=' there, rather than a '<'?

Yes.  When I compile it with gcc on another machine, I get the right
results.

If you have any ideas, please let me know.  Thanks for your help.

Cynthia

> 
> On Tue, 27 Aug 2002, Cynthia Randles wrote:
> 
> > I was wondering if anyone could help me.
> > I have the following lines of code:
> >
> >         for (i = 0; i <=  NUMBINS; ++i)
> >         {
> >               printf("--------read in input files---------\n");
> >               printf("The value if i is %d\n", i);
> >               fscanf(ifp1, "%f\n", &radius_microns);
> >               fscanf(ifp2, "%f\n", &volfraction);
> >               printf("The value of radius is %f\n", radius_microns);
> >               rad_array[i]= radius_microns;
> >
> >               printf("The radius is rad_array[%d]=%f\n\n",i, rad_array[i]);
> >
> >               printf("The value of volfraction is %f\n", volfraction);
> >               vol_array[i] = volfraction;
> >               printf("The volfraction is vol_array[%d]=%f\n", i, vol_array[i]);
> >               printf("The value of rad_array[%i] is %f\n", i, rad_array[i]);
> >               printf("----------end of read in input file------\n\n");
> >         }
> >
> > which, in cygwin produces:
> >
> > --------read in input files---------
> > The value of i is 0
> > The value of radius is 0.200000
> > The radius is rad_array[0] = 0.200000
> >
> > The value of volfraction is 0.330000
> > The volfraction is vol_array[0]=0.330000
> > The value of rad_array[0] is 0.330000
> > ----------end of read in input file-----
> >
> > as you can see, for some reason rad_array[0] is being reassigned even
> > though I never ask for that!!!
> >
> > my red-hat linux gcc produces:
> >
> > --------read in input files---------
> > The value of i is 0
> > The value of radius is 0.200000
> > The radius is rad_array[0] = 0.200000
> >
> > The value of volfraction is 0.330000
> > The volfraction is vol_array[0]=0.330000
> > The value of rad_array[0] is 0.200000
> > ----------end of read in input file-----
> >
> > which is the right answer.  I cannot figure out what is going
> > on with cygwin, and I haven't found a post that can help me.  Any
> > help is appreciated.
> >
> > Thanks,
> > Cynthia
> 
> --
>                                 http://cs.nyu.edu/~pechtcha/
>       |\      _,,,---,,_                [email-masked]
> ZZZzz /,`.-'`'    -.  ;-;;,_            [email-masked]
>      |,4-  ) )-,_. ,\ (  `'-'           Igor Pechtchanski
>     '---''(_/--'  `-'\_) fL     a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!
> 
> It took the computational power of three Commodore 64s to fly to the moon.
> It takes a 486 to run Windows 95.  Something is wrong here. -- SC sig file

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/