* Why can't I used a deferred constant in a case statement?
@ 2015-07-11 15:19 Lucretia
2015-07-13 19:16 ` Randy Brukardt
0 siblings, 1 reply; 2+ messages in thread
From: Lucretia @ 2015-07-11 15:19 UTC (permalink / raw)
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
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.
Luke.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Why can't I used a deferred constant in a case statement?
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
0 siblings, 0 replies; 2+ messages in thread
From: Randy Brukardt @ 2015-07-13 19:16 UTC (permalink / raw)
"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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-13 19:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox