From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: buffer1.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!1.eu.feeder.erje.net!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Why can't I used a deferred constant in a case statement? Date: Mon, 13 Jul 2015 14:16:36 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1436814997 11162 24.196.82.226 (13 Jul 2015 19:16:37 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 13 Jul 2015 19:16:37 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: number.nntp.giganews.com comp.lang.ada:194115 Date: 2015-07-13T14:16:36-05:00 List-Id: "Lucretia" 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.