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,b50bc6538a649497 X-Google-Attributes: gid103376,public From: Robert A Duff Subject: Re: constants v variables (was Re: if statements) Date: 2000/11/09 Message-ID: #1/1 X-Deja-AN: 691680016 Sender: bobduff@world.std.com (Robert A Duff) References: <3A02CED4.520C2768@brighton.ac.uk> <3A078B6F.D34B024B@erols.com> <8ua3m1$bru$1@nnrp1.deja.com> <3A09A39F.2822C01B@cepsz.unizar.es> <8udce8$1qi$1@nnrp1.deja.com> <3a0a6f6c$1@pull.gecm.com> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 2000-11-09T00:00:00+00:00 List-Id: "Martin Dowie" writes: > Thanks for highlighting this one - I've been bleeting on about this locally > (and even in c.l.a. once!) for ages to collegues. Me, too. IMHO, constant should be the *default*, and you should have to say "var" or something to declare a variable; then people would be less likely to make this mistake. In fact, that *is* the way parameters work ("in" is the default). It seems inconsistent that object declarations work differently. >...I've noticed that apart > from the analysis-of-the-problem meaning (i.e. it shows that the value has > been determined to be the same thoughout its scope) there are also > efficiency benefits, at least on one of our target compilers (in > non-optimising mode, untried when optimising). Well, it seems kind of pointless to worry about efficiency if you have optimization turned off. > My question is - can these efficiencies be expected from a compiler, by the > way the ARM defines variables v constants, or is this just because of the > particular compiler we were using. Will any 'decent' compiler spot when a > 'variable' should actually have been declared as a constant? A good compiler will probably be able to spot this if the variable is local (if you turn on the highest optimization level!). For globals (library-package-level), the compiler probably needs the "constant" to tell it the thing is constant. - Bob