Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

QUIZ: To be or not to be (able to post)

0 views
Skip to first unread message

Geert Bosch

unread,
Sep 29, 1997, 3:00:00 AM9/29/97
to

OK, here is a nice question for all you Ada experts out there.
Why isn't the code below not legal? Or is it? If so, why?

with Ada.Numerics.Elementary_Functions;
procedure Renaming is

function Sin (F : Float) return Float;

function Sin (X : Float'Base) return Float'Base
renames Ada.Numerics.Elementary_Functions.Sin;

begin
null;
end Renaming;

What does your favorite compiler say? And the others? ;-)

Regards,
Geert

Matthew Heaney

unread,
Sep 30, 1997, 3:00:00 AM9/30/97
to

In article <60n3dm$fhi$1...@gonzo.sun3.iaf.nl>, Geert Bosch
<ge...@gonzo.sun3.iaf.nl> wrote:

>OK, here is a nice question for all you Ada experts out there.
>Why isn't the code below not legal? Or is it? If so, why?
>
> with Ada.Numerics.Elementary_Functions;
> procedure Renaming is
>
> function Sin (F : Float) return Float;
>
> function Sin (X : Float'Base) return Float'Base
> renames Ada.Numerics.Elementary_Functions.Sin;
>
> begin
> null;
> end Renaming;

Isn't this a "co-resident homograph"? Float is a subtype of Float'Base,
and subtypes can't be used to resolve ambiguity. Only types are part of a
signiture, not subtypes.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew...@acm.org>
(818) 985-1271

Tucker Taft

unread,
Sep 30, 1997, 3:00:00 AM9/30/97
to

Geert Bosch (ge...@gonzo.sun3.iaf.nl) wrote:

: OK, here is a nice question for all you Ada experts out there.
: Why isn't the code below not legal? Or is it? If so, why?

: with Ada.Numerics.Elementary_Functions;
: procedure Renaming is

: function Sin (F : Float) return Float;

: function Sin (X : Float'Base) return Float'Base
: renames Ada.Numerics.Elementary_Functions.Sin;

This is not legal because you use "F" in the declaration of Sin
and you use "X" in the renaming-as-body, and that violates 8.5.4(5) which
requires full conformance of profiles between a renaming-as-body
and the declaration it completes.

On the other hand, it is OK to use Float in one and Float'Base in the
other because subtype Float statically matches subtype Float'Base.
They statically match because they are of the same type,
and they both have the "null" constraint. See 4.9.1(2) and 3.5.7(12).

: ...
: What does your favorite compiler say?

It complains as follows:

6 function Sin (X : Float'Base) return Float'Base
*
*****Error: LRM:8.5.4(5) a renaming-as-body must be fully conformant with the
***** declaration it completes, continuing
7 renames Ada.Numerics.Elementary_Functions.Sin;

: ... And the others? ;-)

I haven't tried any others on this.

: Regards,
: Geert

--
-Tucker Taft s...@inmet.com http://www.inmet.com/~stt/
Intermetrics, Inc. Burlington, MA USA

Joel VanLaven

unread,
Oct 2, 1997, 3:00:00 AM10/2/97
to

Geert Bosch <ge...@gonzo.sun3.iaf.nl> wrote:
: OK, here is a nice question for all you Ada experts out there.
: Why isn't the code below not legal? Or is it? If so, why?

: with Ada.Numerics.Elementary_Functions;
: procedure Renaming is

: function Sin (F : Float) return Float;

: function Sin (X : Float'Base) return Float'Base
: renames Ada.Numerics.Elementary_Functions.Sin;

: begin
: null;
: end Renaming;

: What does your favorite compiler say? And the others? ;-)

Our compiler (PowerAda) says:

6: function Sin (X : Float'Base) return Float'Base

-----------------------------------------------
>>> SEMANTIC: Formal part of renaming-as-body is inconsistent with its
specification <8.5.4:5>


the LRM reference says (just the good part):
"The profile of a renaming-as-body shall ..., and shall conform fully to that
of the declaration it completes"

Fully conformant includes subtype conformant and the two profiles are not
subtype conformant.

-- Joel VanLaven

Tucker Taft

unread,
Oct 2, 1997, 3:00:00 AM10/2/97
to

Joel VanLaven (j...@ocsystems.com) wrote:
: ...
: : function Sin (F : Float) return Float;

: : function Sin (X : Float'Base) return Float'Base
: : renames Ada.Numerics.Elementary_Functions.Sin;

: ...
: Our compiler (PowerAda) says:

: 6: function Sin (X : Float'Base) return Float'Base
: -----------------------------------------------
: >>> SEMANTIC: Formal part of renaming-as-body is inconsistent with its
: specification <8.5.4:5>


: the LRM reference says (just the good part):
: "The profile of a renaming-as-body shall ..., and shall conform fully to that
: of the declaration it completes"

: Fully conformant includes subtype conformant and the two profiles are not
: subtype conformant.

Actually, they *are* subtype conformant, but they are not *fully* conformant
because of the formal parameter name change from F to X. I bet your
compiler knew that already ;-).

: -- Joel VanLaven

Joel VanLaven

unread,
Oct 2, 1997, 3:00:00 AM10/2/97
to

Tucker Taft <s...@houdini.camb.inmet.com> wrote:

: Actually, they *are* subtype conformant, but they are not *fully* conformant


: because of the formal parameter name change from F to X. I bet your
: compiler knew that already ;-).

Sure enough, I goofed. I tried compiling it with the X changed to an F and
it worked so our compiler must have "known that". I am just a little
surprised that the "obvious" big difference (between float and float'base)
wasn't really a difference at all.

Thanks for the catch.

-- Joel VanLaven

Robert A Duff

unread,
Oct 3, 1997, 3:00:00 AM10/3/97
to

In article <6114h5$p...@news3.his.com>,
Joel VanLaven <j...@ocsystems.com> wrote:
>... I am just a little

>surprised that the "obvious" big difference (between float and float'base)
>wasn't really a difference at all.

If you say:

type T1 is range -10..10;
type T2 is digits 5 range -10.0..10.0;

then T1 and T2 are constrained. On the other hand, if you say:

type T3 is digits 5; -- no range given here

then T3 is unconstrained. So T3 is the same thing as T3'Base (both are
unconstrained). But T1 and T1'Base are different, and T2 and T2'Base
are different (T1 and T2 are constrained; T1'Base and T2'Base are
unconstrained).

The predefined floating point types, such as Float, are like T3 in this
regard. That is, Float is unconstrained, so Float is the same thing as
Float'Base. This is because the declaration of Float has no "something
.. something else". See A.1(20).

The predefined integer types, such as Integer, are constrained.

This all makes sense to me. The "surprise" probably comes from the fact
that this is different from Ada 83, where the first subtype was always
constrained in the floating-point case.

- Bob

0 new messages