This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: casting on 64/32-bit environment
Mitja Ursic writes:
> >
> > You're casting from a pointer to an integer. This is the wrong thing
> > to do.
> >
>
> > > Down I give a part of a code:
> > >
> > > //FUNC.CC
> > > void func ()
> > > {
> > > ?
> > > int iel=0;
> > > ?
> > > PtrF <EL> el01 = (EL*) iel; //line 105
> >
> > Don't do this. The answer to your problem is to not cast a pointer to
> > an integer. If you can explain why you want to do such casting, we'll
> > be able to tell you how to avoid it.
> >
> I did not write the program. Structure, which I gave last time, is
> such that enables communication between Fortran and C++ on a way
> that has historical reasons. So the structure is a fact, which
> can't be changed.
Ha, right. FORTRAN: that explains the weirdness.
> There are no problems if the program is compiled on 32-bit
> environment, but on 64-bit environment I get casting warnings.
> The purpose of casting is to initialise arrays used by C++ and
> Fortran. For test I have made a small program with that
> structure. I found out (based also on info from this forum) that if
> I use long instead of int, I do not have warnings any more. This
> seems to be a solution, which I have not implemented yet.
Well, if this data structure is shared with FORTRAN you'll have to do
something similar on the FORTRAN side. It'll be a different type:
INTEGER*8 or somesuch. I'm not a FORTRAN programmer.
But yes, long will work on all gcc targets I'm aware of.
Andrew.