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]

Re: fortran and c pointers in gcc 2.95.2


Toon Moene wrote:

> Maciej Z. Pindera wrote:
> >
> > I recently built gcc 2.95.2 on a DEC Alpha box running OSF v4.(d?).  I
> > compiled and linked some code consisting of Fortran and C routines, the
> > latter mainly used for dynamic memory allocation.
> >
> > Unfortunately, the code bombs during execution time (apparently) due to
> > the compiler's truncation of fortran pointer sizes, resulting in pointer
> > mismatch (4 bits for fortran and 8 bits for C).  I am aware that this
> > problem had existed in earlier versions of gcc; version 2.92.2 was not
> > supposed to do that.  Is there some switch that needs to be set in order
> > to prevent this behavior?
>
> Hmm, without showing us any source code, this will be hard to solve.
> Firstly, Fortran (at least the language compiled by g77) doesn't know of
> the concept of "pointers", so it is hard to deduce (without source code)
> what you mean by "a mismatch (4 bits for fortran and 8 bits for C)
> [pointers] (you probably mean "bytes", here - not "bits").
>
> Secondly, if you try to fool g77 into accepting a pointer returned by a
> C routine as an INTEGER, you're in deep trouble, because the pointer
> will be 8 bytes on the Alpha (and the 64 bit Sparc, and the 64 bit
> PowerPC, and the (always upcoming) Itanium, etc.) but the INTEGER will
> be 4 bytes.
>
> Please show us some source - we showed ours to you :-)

Oops.  It was very late at night, and it wasn't my code.  While I'm aware
that fortran does not use pointers and passes arguments by reference, I
thought that this particular code used LOC (or similar) intrinsics that
return INTEGER*8 pointer-like constructs on DEC_Alphas.  In the event it
turned out that the code did not do this; the error was not compiler but code
generated.

The code uses C routines to dynamically allocate arrays for use in the
Fortran code.  Briefly,the C pointers, and the integers used in Fortran have
to be of the same width in order to insure that the array origin referenced
in Fortran is at the same memory position as that pointed to by the pointer
in the C routine.  So this particular problem was fixed with a simple
declaration of proper integer size.  Now if I could only get it to read an
unformatted file ...
Thanks for your comments,

Maciej


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