Sujet : Re: Ichbiah 2022 compiler mode
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.adaDate : 21. Dec 2024, 22:26:06
Autres entêtes
Organisation : None to speak of
Message-ID : <87frmgwwwh.fsf@nosuchdomain.example.com>
References : 1 2 3 4
User-Agent : Gnus/5.13 (Gnus v5.13)
"Randy Brukardt" <
randy@rrsoftware.com> writes:
[...]
A lot of "variables" in code actually are only written once. In Ada, those
are better modeled as constants. A constant tells the reader that the value
doesn't change during the life of the object, which is easier for analysis
(both human and machine).
[...]
Agreed. But my understanding is that compilers typically do this kind
of analysis anyway, at least when optimization is enabled. For example,
if I write:
N : Integer := 42;
and later refer to the value of N, if the compiler is able to prove to
itself that N is never modified after its initialization, it can replace
a reference to N with the constant 42 (and possibly fold it into other
constant expressions).
Using "constant" for something that isn't going to be modified is good
practice, but I'd say it's for the benefit of the human reader.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */