public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* fortran and c pointers in gcc 2.95.2
@ 2000-09-10  1:42 Maciej Z. Pindera
  2000-09-10 11:53 ` Toon Moene
  0 siblings, 1 reply; 4+ messages in thread
From: Maciej Z. Pindera @ 2000-09-10  1:42 UTC (permalink / raw)
  To: gcc

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?

Regards,

Maciej

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fortran and c pointers in gcc 2.95.2
  2000-09-10  1:42 fortran and c pointers in gcc 2.95.2 Maciej Z. Pindera
@ 2000-09-10 11:53 ` Toon Moene
  2000-09-12 22:48   ` Maciej Z. Pindera
  0 siblings, 1 reply; 4+ messages in thread
From: Toon Moene @ 2000-09-10 11:53 UTC (permalink / raw)
  To: Maciej Z. Pindera; +Cc: gcc

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 :-)

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://g95.sourceforge.net/ (under construction)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fortran and c pointers in gcc 2.95.2
  2000-09-10 11:53 ` Toon Moene
@ 2000-09-12 22:48   ` Maciej Z. Pindera
  2000-09-13 12:40     ` Toon Moene
  0 siblings, 1 reply; 4+ messages in thread
From: Maciej Z. Pindera @ 2000-09-12 22:48 UTC (permalink / raw)
  To: toon, rth; +Cc: gcc

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fortran and c pointers in gcc 2.95.2
  2000-09-12 22:48   ` Maciej Z. Pindera
@ 2000-09-13 12:40     ` Toon Moene
  0 siblings, 0 replies; 4+ messages in thread
From: Toon Moene @ 2000-09-13 12:40 UTC (permalink / raw)
  To: Maciej Z. Pindera; +Cc: rth, gcc

Maciej Z. Pindera wrote:

> I wrote:

[ Please show us the source, so that we can say something intelligent
  about your problem  ... ]

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

Ha !  This shows exactly why it is important to sent an example code
that behaves problematic in the way mentioned:  I didn't even recall the
ancient LOC-on-64-bit-target problems anymore ...

Cheers,

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://g95.sourceforge.net/ (under construction)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-09-13 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-10  1:42 fortran and c pointers in gcc 2.95.2 Maciej Z. Pindera
2000-09-10 11:53 ` Toon Moene
2000-09-12 22:48   ` Maciej Z. Pindera
2000-09-13 12:40     ` Toon Moene

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).