From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Maciej Z. Pindera" To: toon@moene.indiv.nluug.nl, rth@cygnus.com Cc: gcc@gcc.gnu.org Subject: Re: fortran and c pointers in gcc 2.95.2 Date: Tue, 12 Sep 2000 22:48:00 -0000 Message-id: <39BF1507.3AC88694@HiWAAY.net> References: <39BB49BA.F69DB441@HiWAAY.net> <39BBD553.CB2B7289@moene.indiv.nluug.nl> X-SW-Source: 2000-09/msg00248.html 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