comp.lang.ada
 help / color / mirror / Atom feed
* What's with GNAT?
@ 1996-12-26  0:00 BurnsedBW
  0 siblings, 0 replies; 4+ messages in thread
From: BurnsedBW @ 1996-12-26  0:00 UTC (permalink / raw)



The following is a trimmed-down excerpt of a set of functions and
procedures
we have implemented and used successfully for some time on Tartan C30 &
C40
compilers, as well as Rational (formerly Verdix) for the Sun, and DEC for
the
DEC Workstation. Another group has been trying to use this same code with
the
GNAT compiler for the SUN (sorry, I don't know the version--I'm not sure
they
do either!). But the problem seems to come from the conversion of an "out"
parameter. The GNAT compiler says the statement wil raise CONTRAINT_ERROR,
and
if a program is executed it does indeed raise it. Since I am not familiar
enough with GNAT, I offered to post this question for them. As background,
let
me say that this is for a missile system that deals heavily in vectors and
matrices (there are many more than the two types illustrated), and the
system
design often depends on quickly converting real valued vectors from one
type
to another. Sometimes the only difference is in rotating the coordinate
frame.
Hence, we chose the single enumerated type for all indices, with named
subtype
ranges that should allow a simple type-name conversion syntax. And it
works,
and has been tested on the compilers mentioned above. What are missing
about
GNAT?
--------------------------------------------------------------------------
------
   package Global is

      type Real is digits 9;

      type Index_type is
      ( X, Y, Z,
        North, East, Down
      );

      subtype Cartesian_Axes   is Index_type range X     .. Z    ;
      subtype NED_Axes         is Index_type range North .. Down ;

      type General_Vector is array ( Index_type range <> ) of Real ;

      type Cartesian_Vector   is General_Vector( Cartesian_Axes   );
      type NED_Vector         is General_Vector( NED_Axes         );

   end Global;
--------------------------------------------------------------------------
------
   with Global;   
   package Matrix is

      procedure Multiply ( Left, Right : in     Global.Cartesian_Vector;
                           Result      :    out Global.Cartesian_Vector 
);

      procedure Multiply ( Left, Right : in     Global.NED_Vector;
                           Result      :    out Global.NED_Vector  );

   end Matrix;
--------------------------------------------------------------------------
------
   package body Matrix is

      procedure Multiply ( Left, Right : in     Global.Cartesian_Vector;
                           Result      :    out Global.Cartesian_Vector  )
is
      begin  -- Multiply
         ... code to perform matrix mulitplication ...
      end Multiply;


      procedure Multiply ( Left, Right : in     Global.NED_Vector;
                           Result      :    out Global.NED_Vector  );
      begin  -- Multiply
         Multiply ( Global.Cartesian(Left), Global.Cartesian(Right),
                    Global.NED_Vector(Result)                         );
 -------------------^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------- claims it will raise CONSTRAINT_ERROR--and does!
      end Multiply;

   end Matrix;
--------------------------------------------------------------------------
------

Thanks,
-----
 BwB




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

* Re: What's with GNAT?
@ 1996-12-27  0:00 Sazonov Cyril
  1996-12-28  0:00 ` burnsedbw
  0 siblings, 1 reply; 4+ messages in thread
From: Sazonov Cyril @ 1996-12-27  0:00 UTC (permalink / raw)



BwB wrote us:

.................
> the GNAT compiler for the SUN (sorry, I don't know the version--I'm not sure
> they do either!). But the problem seems to come from the conversion of an
> "out" parameter. The GNAT compiler says the statement wil raise
> CONTRAINT_ERROR, and if a program is executed it does indeed raise it. Since
> I am not familiar enough with GNAT, I offered to post this question for them.
..................................
> What are missing about GNAT?
..................................
>      procedure Multiply ( Left, Right : in     Global.Cartesian_Vector;
>                           Result      :    out Global.Cartesian_Vector );
..................................
>
>      procedure Multiply ( Left, Right : in     Global.NED_Vector;
>                           Result      :    out Global.NED_Vector  );
>      begin  -- Multiply
>         Multiply ( Global.Cartesian(Left), Global.Cartesian(Right),
>                    Global.NED_Vector(Result)                         );
> -------------------^^^^^^^^^^^^^^^^^^^^^^^^^
>-------------------- claims it will raise CONSTRAINT_ERROR--and does!
>      end Multiply;

I suppose you are missing about the _language_, but not _GNAT_. It seems me
that the thing is that the reurned result is of Global.Cartesian_Vector type
even though the variable Result is of Global.NED_Vector and the type
conversion is to be done _before_ assignment, perfomed by the result return.
So you are to use an intermediate variable to be able to _get_ the wanted
result and the cjnvert it. For example:

      procedure Multiply ( Left, Right : in     Global.NED_Vector;
                           Result      :    out Global.NED_Vector  );

         INTERIM : Global.Cartesian_Vector;

      begin  -- Multiply
         Multiply ( Global.Cartesian(Left), Global.Cartesian(Right),
                    INTERIM ) ;
         Result := Global.NED_Vector ( INTEGRIM ) ;
      end Multiply;

Happy New Year !

Best wishes from Russia !                             Cyril Sazonov





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

* Re: What's with GNAT?
  1996-12-27  0:00 Sazonov Cyril
@ 1996-12-28  0:00 ` burnsedbw
  0 siblings, 0 replies; 4+ messages in thread
From: burnsedbw @ 1996-12-28  0:00 UTC (permalink / raw)



Sazonov Cyril <cyril@geol.spb.su> said...

> I suppose you are missing about the _language_, but not _GNAT_. It seems
me
> that the thing is that the reurned result is of Global.Cartesian_Vector
type
> even though the variable Result is of Global.NED_Vector and the type
> conversion is to be done _before_ assignment, perfomed by the result
return.
> So you are to use an intermediate variable to be able to _get_ the
wanted
> result and the cjnvert it. For example:

This is the second reply I received suggesting there is something
syntactically
wrong with conversion of an "out" parameter. However, I believe the LRM
para
6.4.1 (4) clearly states that conversion occurs in _both_ directions. As I
have
implied, this works (quite well) on every compiler I have ever used. I
have never
used GNAT, but I have used at least six other validated (Ada '83)
compilers. For
reasons I will not take time to mention, we consciously chose to avoid
declaring
intermediate variables whenever possible.

But thanks for trying...
-----
 BwB




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

* Re: What's with GNAT?
@ 1996-12-30  0:00 Sazonov Cyril
  0 siblings, 0 replies; 4+ messages in thread
From: Sazonov Cyril @ 1996-12-30  0:00 UTC (permalink / raw)



BwB wrote me:

> However, I believe the LRM para 6.4.1 (4) clearly states that conversion
> occurs in _both_ directions.

As I can see it is high time for me to re-read the LRM !

> For reasons I will not take time to mention, we consciously chose to avoid
> declaring intermediate variables whenever possible.

As for me, I don't like them too. But sometimes....

And what about functions ? Or just operations ? Something like this :

      function  Multiply ( Left, Right : in     Global.Cartesian_Vector )
                        return Global.Cartesian_Vector ;
..........................................................................
      function  Multiply ( Left, Right : in     Global.NED_Vector )
                        return Global.NED_Vector is
      begin  -- Multiply
         return Global.NED_Vector ( Multiply ( Global.Cartesian(Left),
                                               Global.Cartesian(Right) ) ;
      end Multiply;

or better ( on my taste, this is the best way at all ) :

      function "*" ( Left, Right : in Global.Cartesian_Vector )
                  return Global.Cartesian_Vector ;
..................................
      function "*" ( Left, Right : in     Global.NED_Vector;
                  return Global.NED_Vector is
      begin  -- Multiply
         return Global.NED_Vector ( Global.Cartesian(Left) *
                                    Global.Cartesian(Right) ) ;
      end Multiply;


Happy New Year !

Best wishes from Russia !                             Cyril Sazonov




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

end of thread, other threads:[~1996-12-30  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-26  0:00 What's with GNAT? BurnsedBW
  -- strict thread matches above, loose matches on Subject: below --
1996-12-27  0:00 Sazonov Cyril
1996-12-28  0:00 ` burnsedbw
1996-12-30  0:00 Sazonov Cyril

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