comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <dewar@gnat.com>
Subject: Re: Ada95 + FORTRAN 77
Date: 1999/09/06
Date: 1999-09-06T00:00:00+00:00	[thread overview]
Message-ID: <7r0u2o$vik$1@nnrp1.deja.com> (raw)
In-Reply-To: m3so4sgprj.fsf@kiuk0156.chembio.ntnu.no

In article <m3so4sgprj.fsf@kiuk0156.chembio.ntnu.no>,
  Preben Randhol <randhol@pvv.org> wrote:
> Thanks! It worked very nice. I also noticed that one have to
be
> careful with the variable types. Changing, in the F77 program,
REAL*4
> to DOUBLE PRECISION resulted in a bug in the output. But when
I added
> Interfaces.Fortran and used Double_Precision it worked fine
again :-)


Well yes, of course you must be careful to have corresponding
types, and typically systems will not be able to check this
in Ada-Fortran interfacing (actually most Fortran compilers
don't even check this in Fortran-Fortran interfacing).

Do if you are using DOUBLE PRECISION in the Fortran program,
you must use Interfaces.Fortran.Double_Precision.

In GNAT, you can simply use Long_Float, and this will always
work, because GNAT always defines

   type Fortran_Integer  is new Integer;
   type Real             is new Float;
   type Double_Precision is new Long_Float;

One other point is to be careful of type Logical in the
Fortran interface. This is defined to be a new Boolean, but
with very unusual (zero/non-zero) semantics.

There are no ACVC tests to ensure that this is done right, and
it is quite a lot of specialized mechanism in the compiler to
deal with this very non-standard Boolean type. So if you rely
on this, be careful to check that your compiler handles this.

The proper handling of Fortran Logical was only recently added
to GNAT (for version 3.12). At the same time, we also
implemented a rather nice feature:

  type C_Bool is new Boolean;
  pragma Convention (C, C_Bool);

the semantics of this boolean will be like C, zero/non-zero,
rather than normal Ada representation semantics. This can make
interfacing to booleans in C quite a bit cleaner and more
abstract (otherwise you have to explicitly treat the C logical
values as integers on the Ada sign with zero/non-zero semantics)

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




  reply	other threads:[~1999-09-06  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-06  0:00 Ada95 + FORTRAN 77 Preben Randhol
1999-09-06  0:00 ` lafage8770
1999-09-06  0:00   ` Matthew Heaney
1999-09-06  0:00     ` Robert Dewar
1999-09-06  0:00   ` Preben Randhol
1999-09-06  0:00     ` Robert Dewar [this message]
1999-09-06  0:00       ` Preben Randhol
1999-09-06  0:00         ` Robert Dewar
1999-09-07  0:00           ` Preben Randhol
1999-09-08  0:00             ` Robert Dewar
1999-09-07  0:00       ` okellogg
1999-09-08  0:00         ` Robert Dewar
1999-09-06  0:00 ` Gisle S�lensminde
1999-09-06  0:00   ` Preben Randhol
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox