Академический Документы
Профессиональный Документы
Культура Документы
PROGRAMMING POINTERS
Dan Saks
strictly conforming program. That is, the those conversion rules in “What const
program won’t execute properly on Really Means,” August 1998, p. 11.)
some standard C platforms. For example:
Often, the clearest and most direct way to explain the behavior of a program
construct is to describe how it executes on some representative computer. declare const objects as auto variables
This is what the C standard tries to do. and write-protect them at run time.
I’m not aware of any architecture that
actually does this, but if you know of
one, please let me know.
A footnote in the standard summa- • The implementation may place a
rizes the freedom that C implementa- const object with static storage that is Errata
tions have to place data into ROM: not volatile in a read-only region of
storage My previous column (“Volatile
• The implementation may place a Objects,” September 1998, p. 101)
const object that is not volatile in a An object can’t very well reside in contained numerous program frag-
read-only region of storage ROM unless it has a fixed address ments built around a loop of the form:
determined at translation time. Maybe
A C compiler cannot place an omitting the phrase “with static stor- while (*pc & READY == 0)
object into ROM if it’s volatile as well age” was an oversight, but maybe it /* do nothing until ready */;
as const. The value of a volatile object wasn’t.
might be changed by events outside I suppose this wording allows for an Reader Don Starr pointed out that
the program’s control. An object can’t architecture that can write-protect the condition in the loop does not do
exhibit volatile behavior if it resides in RAM at run time. Write-protected as I intended. Whereas && has a higher
ROM. RAM is not ROM in the sense that I precedence than ==, & has a lower
I’m a little intrigued by the exact think most embedded programmers precedence. As written, the loop is
wording of the footnote. I expected it speak of ROM, but it’s ROM nonethe- equivalent to:
to say something like: less. In theory, a program could
while (*pc & (READY == 0))
/* do nothing until ready */;