comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier.DeMontmollin@maths.unine.ch
Subject: Re: Conditional Code in Ada 95?
Date: 1998/08/24
Date: 1998-08-24T00:00:00+00:00	[thread overview]
Message-ID: <mNNTgiTaiASf@nedcu4> (raw)
In-Reply-To: 6ro33g$kb$1@nnrp1.dejanews.com

(...)
>>  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





  reply	other threads:[~1998-08-24  0:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-21  0:00 Conditional Code in Ada 95? Rex Reges
1998-08-21  0:00 ` Gene Ouye
1998-08-24  0:00   ` Mark A Biggar
1998-08-27  0:00     ` Samuel T. Harris
1998-08-27  0:00       ` David C. Hoos, Sr.
1998-08-22  0:00 ` dewarr
1998-08-22  0:00 ` Gautier.DeMontmollin
1998-08-23  0:00   ` dewar
1998-08-24  0:00     ` Gautier.DeMontmollin [this message]
1998-08-24  0:00   ` Michael F Brenner
1998-08-25  0:00     ` dewarr
1998-08-25  0:00       ` Richard D Riehle
1998-08-26  0:00         ` dennison
1998-08-26  0:00           ` Richard D Riehle
1998-08-27  0:00             ` dennison
1998-08-26  0:00       ` Michael F Brenner
1998-08-25  0:00     ` Jean-Pierre Rosen
1998-08-28  0:00       ` Laurent Pautet
replies disabled

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