comp.lang.ada
 help / color / mirror / Atom feed
* Operator visibility: why are modular types different??!
@ 1996-05-03  0:00 Geert Bosch
  1996-05-04  0:00 ` Robert A Duff
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Bosch @ 1996-05-03  0:00 UTC (permalink / raw)



Recently I encountered a really nasty problem, which I find hard 
to work around. The situation is that I want to create a package
that provides some types which are subtypes of Interfaces.C. 
(Example:  subtype ULONG is Interfaces.C.unsigned_long)  

I want these types to be subtypes instead of new types, so 
the conversion functions from Interfaces.C can be used without 
extra conversions.

On the other had, I want the user to directly use my ULONG type
without having to bother about Interfaces.C.  To make operations
like = visible, I put ``use type ULONG'' in the spec of my package.
For normal integer types this works as expected, but not for modular
types. What's the difference and where can I find that in the RM?

Below is a complete example to make my problem clear. The compiler
is GNAT v3.01.

I'm really looking forward to an answer!

Regards,
   Geert

PS. Please CC. to geert@sun3.iaf.nl since my news is unreliable :-(

(WARNING: THIS PROBABLY IS NOT VALID ADA CODE!)

procedure UseTest is

   package A is
--      type I is range 0..2**32 - 1;   -- Program compiles with this def.
      type I is mod 2**32;		-- This gives visibility error
   end A;

   package B is
      subtype J is A.I;
      use type J;
   end B;

   use B;

   X   : J := 1;

begin
   if X /= 1 then
      null;
   end if;
end UseTest;

-- 
E-Mail: geert@sun3.iaf.nl     *** As far as we know, there have not been ***
 Phone: +31-53-4303054        ** any undetected failures in our software. **




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

* Re: Operator visibility: why are modular types different??!
  1996-05-03  0:00 Operator visibility: why are modular types different??! Geert Bosch
@ 1996-05-04  0:00 ` Robert A Duff
  0 siblings, 0 replies; 2+ messages in thread
From: Robert A Duff @ 1996-05-04  0:00 UTC (permalink / raw)



In article <4mbcuu$4ne@fozzie.sun3.iaf.nl>,
Geert Bosch <geert@fozzie.sun3.iaf.nl> wrote:
>procedure UseTest is
>
>   package A is
>--      type I is range 0..2**32 - 1;   -- Program compiles with this def.
>      type I is mod 2**32;		-- This gives visibility error
>   end A;
>
>   package B is
>      subtype J is A.I;
>      use type J;
>   end B;
>
>   use B;
>
>   X   : J := 1;
>
>begin
>   if X /= 1 then

This is illegal.  The "use type J" makes the operators directly visible
inside B.  But use clauses are not transitive.  The "use B" makes things
declared in B directly visible.  It does not grab everything directly
visible in B.

If you moved the "use type J" outside B, then it would work.

There is no difference between signed integers and modular integers in
this respect.  So it sounds like it may be a compiler bug, that the
compiler didn't detect the error in the signed case.

- Bob




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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-03  0:00 Operator visibility: why are modular types different??! Geert Bosch
1996-05-04  0:00 ` Robert A Duff

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