From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Why can't I used a deferred constant in a case statement?
Date: Mon, 13 Jul 2015 14:16:36 -0500
Date: 2015-07-13T14:16:36-05:00 [thread overview]
Message-ID: <mo12ql$asq$1@loke.gir.dk> (raw)
In-Reply-To: f5e52fb4-f3a4-4c81-8d20-57b3a0d4f581@googlegroups.com
"Lucretia" <laguest9000@googlemail.com> wrote in message
news:f5e52fb4-f3a4-4c81-8d20-57b3a0d4f581@googlegroups.com...
> Hi,
>
> In my SDL bindings, I made all my event constants deferred, but when I
> came to use them in a case statement, the compiler complained:
>
> test.adb:61:24: choice given in case statement is not static
> test.adb:64:24: choice given in case statement is not static
Looks right to me.
> The code is:
>
> declare
> Event : SDL.Events.Events;
> Finished : Boolean := False;
>
> use type SDL.Events.Event_Types;
> begin
> loop
> while SDL.Events.Poll (Event) loop
> case Event.Common.Event_Type is
> when SDL.Events.Quit => -- 61
> Finished := True;
>
> when SDL.Events.Key_Up => -- 64
> SDL.Log.Put_Debug
> ("Key up event: " &
> SDL.Events.Key_Codes'Image
> (Event.Keyboard.Key_Sym.Key_Code));
> when others =>
> null;
> end case;
> end loop;
>
> exit when Finished;
> end loop;
> end;
>
> Where Quit and Key_Up are deferred:
>
> package SDL.Events is
> type Event_Types is mod 2 ** 32 with
> Convention => C;
>
> Quit : constant Event_Types;
> Key_Up : constant Event_Types;
> private
> Quit : constant Event_Types := 16#0000_0100#;
> Key_Up : constant Event_Types := Key_Down + 1;
> end SDL.Events;
>
> I can't find anything about this anywhere.
There's nothing to find. Deferred constants aren't in the list in 4.9. And
that makes sense, because if they could be static, you'd have a privacy
breakage (you'd be depending on the contents of the private part). After
all, the full definition of the constant might be non-static:
private
Base : constant Event_Types := Event_Types(Random_Func);
Quit : constant Event_Types := Base;
Key_Up : constant Event_Types := Base + 1;
end SDL.Events;
Since you want to use these in case statements, you can't hide the values
(the compiler and reader both need to know the values involved), so deferred
constants are inappropriate.
Randy.
prev parent reply other threads:[~2015-07-13 19:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-11 15:19 Why can't I used a deferred constant in a case statement? Lucretia
2015-07-13 19:16 ` 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