comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: no + or - defined for fixed point types in Standard, why ?
Date: Thu, 25 Jan 2018 22:34:31 -0600
Date: 2018-01-25T22:34:31-06:00	[thread overview]
Message-ID: <p4eb4n$aa8$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 3c342468-67da-4973-a318-14e0cf1293fb@googlegroups.com

"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:3c342468-67da-4973-a318-14e0cf1293fb@googlegroups.com...
> generic
>   type Modele is delta <>;
> package P_Proba1 is
>   type T_Proba is private;
>   function "+" (
>         Un,
>         Deux : in     T_Proba )
>     return T_Proba;
> private
> type T_proba is new MODELE range 0.1..1.0;
> end P_Proba1;
>
> package body P_Proba1 is
> function "+"
>     (Un,
>         Deux : in     T_Proba)
>        return T_Proba is (P_Proba1."+"(UN,Deux));
> end P_Proba1;
>
>> program, you have to prefix by the package name that contains the 
>> operators : My code.
> It causes infinite recursion (dixit compiler), so I didn't understand.

Yup, that calls the operator you just defined, and not the original one. In 
this case, there is no way to get to the original operator of T_Proba; 
you've hidden it with the new one. (This is a common Ada programming mistake 
when defining operators, happens to me all the time.) You have to use some 
other type's "+" operator with type conversions. In this case, you might as 
well use the operators of Modele (which are declared with it at the formal 
type declaration):

T_Proba (Modele (Un) + Modele (Deux));

There's a way to get at the original operator using renames, but it isn't 
worth the headache unless you don't have a similar type that you can convert 
to.

                                   Randy.



      reply	other threads:[~2018-01-26  4:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 17:03 no + or - defined for fixed point types in Standard, why ? Mehdi Saada
2018-01-24 17:44 ` Robert Eachus
2018-01-24 18:36   ` Mehdi Saada
2018-01-25  1:09     ` Robert Eachus
2018-01-25  1:31       ` guyclaude.burger
2018-01-25  3:07         ` Robert Eachus
2018-01-25  3:25 ` Randy Brukardt
2018-01-25 13:33   ` Mehdi Saada
2018-01-26  4:34     ` Randy Brukardt [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