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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ec2b9b815bd3b0bd X-Google-Attributes: gid103376,public From: Gautier.DeMontmollin@maths.unine.ch Subject: Re: Conditional Code in Ada 95? Date: 1998/08/24 Message-ID: #1/1 X-Deja-AN: 384157142 References: <35DDFB42.1311@boeing.com> <2$$CdIjQwTPX@nedcu4> <6ro33g$kb$1@nnrp1.dejanews.com> Organization: University of Neuchatel, Switzerland Newsgroups: comp.lang.ada Date: 1998-08-24T00:00:00+00:00 List-Id: (...) >> debug: boolean:= false; >> verbose: boolean:= true; >> begin >> if debug then put_line("this is for debug"); end if; >> if verbose then put_line("verbosity"); end if; >> end; > I would think that virtually any Ada compiler would delete > the dead code if the booleans are constant, but asking for > the deletion in the variable case is a bit more strenuous. > Note that there is absolutely NO reason that these are > variables rather than constants in your example. Remember > an important rule in Ada is that you ALWAYS use the constant > keyword whereever you can. I had forgotten the "constant" keyword in my example - sigh... Of course a variable is a bit inappropriated for conditional compiling... > GNAT will most certainly delete the code in question whether > or not a constant keyword is present. Tested: Without optimization, the variable is tested and in the constant case a JMP is performed over the unused code. With -O1 or better, the unusued code is deleted in any case (in the variable case, it means that the optimizer sees that the "debug" variable was not modified from its initial value "false" at that moment!). It's interesting to note that "this is for debug" string is kept in data, even though the code that could reference it has disappeared... Of course this optimisation is made at a later step of code generation, I guess. -- Gautier