comp.lang.ada
 help / color / mirror / Atom feed
From: stt@henning.camb.inmet.com (Tucker Taft)
Subject: Re: Using complex from interfaces.fortran.
Date: Tue, 28 Feb 1995 22:21:13 GMT
Date: 1995-02-28T22:21:13+00:00	[thread overview]
Message-ID: <D4qE3D.CuE@inmet.camb.inmet.com> (raw)
In-Reply-To: 1995Feb22.164009.16834@driftwood.cray.com

Brian Hanson (brh@cray.com) wrote:

: I was looking at the package Interfaces.Fortran.  Suppose you want to work
: with complex numbers.  There is a type defined in this package called Complex
: and you can do all the normal stuff with it but suppose you wish to output a
: complex number.  How to do it?

: with Interfaces.Fortran; use Interfaces.fortran;
: with ada.text_io.complex_io;
: procedure test is
:   package complex_io is new ada.text_io.complex_io
: 	(single_precision_complex_types);
:   with complex_io;
    ^^^^ "use" presumably

:   a, b, c: complex;

: begin
:   a := (1.7, 2.8);
:   b := (9.5, 6.2);

:   c := a * b + complex'(2.3, 0.0);
:   put(c);
: end;

: My expectation is that the put not compile because it expects the type
: single_precision_complex_types.complex and not the complex defined in 
: fortran.

: Is this true.  

Yes, that is your problem.

: ... If so, does it not make using complex from package fortran
: very awkward for io and functions like sin, cos which are also accessed
: via a generic package with a package parameter?

Yes, this seems like an unintended consequence of making
Interfaces.Fortran.Complex a derived type.  A subtype would
probably have been better, though that would require the
user to do a "use type Interfaces.Fortran.Complex" rather
than a "use Interfaces.Fortran" to get direct visibility
to the operators (not so terrible IMHO).  Oh well, you can't
win them all.

In any case, you can work around the problem in two ways.
One, insert an explicit conversion in the call on "Put", e.g.:

   Put(Single_Precision_Complex_Types.Complex(C));

or two, avoid use of Interfaces.Fortran.Complex and instead
use Interfaces.Fortran.Single_Precision_Complex_Types.Complex
directly.  In the latter case, you might want to locally
declare "Complex" to be a subtype of 
Single_Precision_Complex_Types.Complex and then do a
"use type Complex;"

: -- Brian Hanson
: -- brh@cray.com

: ps. I attempted to try this with gnat 2.03 but got compile errors for
: the package instantiation.  So I do not know if it is gnat that is wrong
: or my program that is wrong.

The instantiation looks OK.  GNAT might not fully support
formal package parameters yet; send a report to gnat-report
to find out for sure.

-Tucker Taft   stt@inmet.com



      reply	other threads:[~1995-02-28 22:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-02-22 22:40 Using complex from interfaces.fortran Brian Hanson
1995-02-28 22:21 ` Tucker Taft [this message]
replies disabled

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