Deutsch   English   Français   Italiano  
<vk6u92$10a5$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Chris Townley <news@cct-net.co.uk>
Newsgroups: comp.lang.ada
Subject: Re: Ichbiah 2022 compiler mode
Date: Sat, 21 Dec 2024 17:35:30 +0000
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <vk6u92$10a5$1@dont-email.me>
References: <vbc625$at65$1@dont-email.me> <vbdgs7$hedr$1@dont-email.me>
 <vk4uee$3lfp0$1@dont-email.me> <vk5tc9$3uoku$1@dont-email.me>
 <vk6tag$4tm1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 21 Dec 2024 18:35:31 +0100 (CET)
Injection-Info: dont-email.me; posting-host="985a78544156c9e6ba1a1944dc40e630";
	logging-data="33093"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18TrW1L6sbKvG5+FekMwZ07jHaxSDVNmHs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:y/xD6KLtapofQ//XmdCIvwEwev8=
Content-Language: en-GB
In-Reply-To: <vk6tag$4tm1$1@dont-email.me>
Bytes: 2892

On 21/12/2024 17:19, G.B. wrote:
> On 21.12.24 09:14, Randy Brukardt wrote:
> 
>>> Note that :
>>> 1. I have no statistics, but it seems to me that there is more variables
>>> than constants in my code.
>>
>> But how many of them *have* to be variables vs. the number that just are
>> because it is easier? I know I have a number of the latter.
>>
>>> 2. I say "Useless" from my coder point of view, I dont know if it 
>>> simplify
>>> the work for compiler or tools implementers.
>>
>> Constants do help the compiler generate better code, although a lot of 
>> the
>> benefits can be gained also by working harder. (That's what C 
>> compilers do,
>> after all.)
> 
> What are some compilers offering today? That is, can they find declarations
> of variables that could be constants, if so instructed?
> I am seeing some warnings about non-initialized variables for a meaningless
> mock-up, but not much else.  Ada, C++, Java.
> (Maybe there are options that I have missed. Or an analysis of a whole
> program yields more.)
> 
> function testc (b : Boolean) return Integer is
>     package P is
>       x : Integer;
>     end;
> begin
>    if b then
>       P.x := 42;
>    end if;
>    return P.x;
> end testc;
> 
> int testc(bool b) {
>     struct {
>       int x;
>     } P;
>     if (b) {
>       P.x = 42;
>     }
>     return P.x;
> }
> 
> class testc {
>    class P {
>      int x;
>    }
>    P P;
>    int $(boolean b) {
>      if (b) {
>         P.x = 42;
>      }
>      return P.x;
>    }
> }
> 

My understanding is that many compliers will optimise these, and if 
trivial numbers will 'optimise' out the variable. Confusing in the debugger!

-- 
Chris