TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Bill Birrell
from: George White
date: 1998-10-03 09:17:04
subject: Tutorial questions?

Hi Bill,

You wrote to me:

BB> > ?????
BB> > If "const" used no memory a lot of code would break.
BB> > It is just compiler
BB> > information, like "static", and does not remove the
BB> > need for memory for
BB> > the variable marked as "const".

BB>    See 6.5.3. Note 97, George. He is right if and only if the address of th
BB>identifier type-qualified as const is never used. It *is*
BB>possible to write such code in C. Static is also more then
BB>just compiler information. It is one of the three storage
BB>duration specifiers - static, auto or allocated.

So his bold assertation that a "const" qualified variable didn't use any
memory still isn't true. The compiler optimiser is free to treat it like
a #define if, and only if, it is not volatile or it is not referenced by
address, otherwise is is just a special case of a normal variable.

As I see it "static, auto or allocated" as storage duration specifiers
are compiler information, as they tell the compiler extra information
about a variable. We'd better agree to differ here.

BB>    Everybody seems to miss the point that an identifier
BB>type-qualified as const is NOT a variable at all. It is a
BB>constant. The difference is fundamental, particularly in
BB>calculus.

Not so, as I see it. A variable type-qualified as "const" cannot be
changed by the code, there is nothing to stop something else with
access to the variable (in shared memory) changing the variable. It is a
way of saying that a value is read only, and allowing the compiler to
trap any errors in the code involving writing to the code (and I've had
to fight to find bugs in other languages and assembler where a variable
was "changed" in the code but was in reality in ROM and so fixed in
value. Such bugs take a lot of finding :-( ).

BB>    I do not have an abstract machine, so the vagaries of
BB>volatile consts during side effects are completely lost on
BB>me. :-) I suspect that they would still be lost on me if
BB>somebody gave me an abstract machine. :-)

I have situation in a commercial application where variables are
correctly "volatile const" and that is on a very real machine (this one
).

George

 * SLMR 2.1a * Computers eliminate spare time.

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717904) (2:440/4)
SEEN-BY: 396/1 632/0 371 633/260 267 270 371 634/397 635/506 728 810 639/252
SEEN-BY: 670/218
@PATH: 440/4 255/1 251/25 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.