comp.lang.ada
 help / color / mirror / Atom feed
* Unchecked_Union with empty variant
@ 2009-03-15 13:02 Ivan Levashew
  0 siblings, 0 replies; 6+ messages in thread
From: Ivan Levashew @ 2009-03-15 13:02 UTC (permalink / raw)


[Check_Unions.adb



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

* Unchecked_Union with empty variant
@ 2009-03-15 13:10 Ivan Levashew
  0 siblings, 0 replies; 6+ messages in thread
From: Ivan Levashew @ 2009-03-15 13:10 UTC (permalink / raw)


[Check_Unions.adb



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

* Unchecked_Union with empty variant
@ 2009-03-15 13:34 Ivan Levashew
  2009-03-16 15:16 ` Adam Beneschan
  2009-03-16 21:52 ` Stephen Leake
  0 siblings, 2 replies; 6+ messages in thread
From: Ivan Levashew @ 2009-03-15 13:34 UTC (permalink / raw)


[Check_Unions.adb]
~~~~~~~~
procedure Check_Unions is


type Complex_Record (Kind : Integer := 0) is record
    Constant_Part : Character;
    Constant_Part2 : Character;
    case Kind is
    when 0 =>
      Variant_Part1 : Character;
    when 1 =>
      Variant_Part2 : Character;
    when 2 =>
      Variant_Part3 : Character;
    when others =>
      null;
    end case;
end record;

pragma Unchecked_Union (Complex_Record);

begin
    null;
end Check_Unions;
~~~~~~~~

It gives an error:
C:\...ramming\GEMA-Win32API\Ada_test>gnatmake -gnat05 Check_Unions.adb
gcc -c -gnat05 check_unions.adb
check_unions.adb:14:04: Unchecked_Union may not have empty component list
gnatmake: "check_unions.adb" compilation error

What's the problem?

I can't see any words "empty" or "null" here:

http://www.adaic.com/standards/05aarm/html/AA-B-3-3.html

-- 
If you want to get to the top, you have to start at the bottom



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

* Re: Unchecked_Union with empty variant
  2009-03-15 13:34 Unchecked_Union with empty variant Ivan Levashew
@ 2009-03-16 15:16 ` Adam Beneschan
  2009-03-16 21:52 ` Stephen Leake
  1 sibling, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 2009-03-16 15:16 UTC (permalink / raw)


On Mar 15, 6:34 am, Ivan Levashew <octag...@bluebottle.com> wrote:
> [Check_Unions.adb]
> ~~~~~~~~
> procedure Check_Unions is
>
> type Complex_Record (Kind : Integer := 0) is record
>     Constant_Part : Character;
>     Constant_Part2 : Character;
>     case Kind is
>     when 0 =>
>       Variant_Part1 : Character;
>     when 1 =>
>       Variant_Part2 : Character;
>     when 2 =>
>       Variant_Part3 : Character;
>     when others =>
>       null;
>     end case;
> end record;
>
> pragma Unchecked_Union (Complex_Record);
>
> begin
>     null;
> end Check_Unions;
> ~~~~~~~~
>
> It gives an error:
> C:\...ramming\GEMA-Win32API\Ada_test>gnatmake -gnat05 Check_Unions.adb
> gcc -c -gnat05 check_unions.adb
> check_unions.adb:14:04: Unchecked_Union may not have empty component list
> gnatmake: "check_unions.adb" compilation error
>
> What's the problem?
>
> I can't see any words "empty" or "null" here:
>
> http://www.adaic.com/standards/05aarm/html/AA-B-3-3.html

I can't find any rule that makes this illegal.  The error message
indicates, though, that someone at GNAT thought it was illegal---i.e.
it's not simply a "bug" due to incorrectly implementating the
requirements, but was rather a misinterpretation of the standard.  But
either way, I think the compiler is wrong.

                             -- Adam






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

* Re: Unchecked_Union with empty variant
  2009-03-15 13:34 Unchecked_Union with empty variant Ivan Levashew
  2009-03-16 15:16 ` Adam Beneschan
@ 2009-03-16 21:52 ` Stephen Leake
  2009-03-17  7:21   ` Ivan Levashew
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Leake @ 2009-03-16 21:52 UTC (permalink / raw)


Ivan Levashew <octagram@bluebottle.com> writes:

> [Check_Unions.adb]
> ~~~~~~~~
> procedure Check_Unions is
>
>
> type Complex_Record (Kind : Integer := 0) is record
>    Constant_Part : Character;
>    Constant_Part2 : Character;
>    case Kind is
>    when 0 =>
>      Variant_Part1 : Character;
>    when 1 =>
>      Variant_Part2 : Character;
>    when 2 =>
>      Variant_Part3 : Character;
>    when others =>
>      null;
>    end case;
> end record;
>
> pragma Unchecked_Union (Complex_Record);
>
> begin
>    null;
> end Check_Unions;
> ~~~~~~~~
>
> It gives an error:
> C:\...ramming\GEMA-Win32API\Ada_test>gnatmake -gnat05 Check_Unions.adb
> gcc -c -gnat05 check_unions.adb
> check_unions.adb:14:04: Unchecked_Union may not have empty component list
> gnatmake: "check_unions.adb" compilation error
>
> What's the problem?
>
> I can't see any words "empty" or "null" here:
>
> http://www.adaic.com/standards/05aarm/html/AA-B-3-3.html

There is 14/2:

    All objects of an unchecked union type have the same size.

GNAT may be interpreting that to mean all variants must be the same
size. But that's not true, it accepts an Integer:

   type Complex_Record (Kind : Integer := 0) is record
      Constant_Part : Character;
      Constant_Part2 : Character;
      case Kind is
      when 0 =>
         Variant_Part1 : Character;
      when 1 =>
         Variant_Part2 : Integer;
      when 2 =>
         Variant_Part3 : Character;
      when others =>
         Variant_Part4 : Character;
      end case;
   end record;

So it looks like a compiler bug.

-- 
-- Stephe



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

* Re: Unchecked_Union with empty variant
  2009-03-16 21:52 ` Stephen Leake
@ 2009-03-17  7:21   ` Ivan Levashew
  0 siblings, 0 replies; 6+ messages in thread
From: Ivan Levashew @ 2009-03-17  7:21 UTC (permalink / raw)


GNAT supported Unchecked_Union in Ada 95 mode. UU wasn't in Ada 95 
standard, and GNAT could only handle pure union (without declarative 
part). Ada 2005 allowed declarative parts.

I have a theory that GNAT developers allowed declarative parts but 
forgot to disable restriction applicable to records meant to be union 
mirrors.

Anyway I have to deal with current tools so I defined several Union_n 
subtypes.

-- 
If you want to get to the top, you have to start at the bottom



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

end of thread, other threads:[~2009-03-17  7:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-15 13:34 Unchecked_Union with empty variant Ivan Levashew
2009-03-16 15:16 ` Adam Beneschan
2009-03-16 21:52 ` Stephen Leake
2009-03-17  7:21   ` Ivan Levashew
  -- strict thread matches above, loose matches on Subject: below --
2009-03-15 13:10 Ivan Levashew
2009-03-15 13:02 Ivan Levashew

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