Expert C Programming

(Jeff_L) #1

The symbol appearing on the left of an assignment is sometimes called an l-value (for "left-hand-side"
or "locator" value), while a symbol on the right of an assignment is sometimes called an r-value (for
"right-hand-side"). The compiler allocates an address (or l-value) to each variable. This address is
known at compiletime, and is where the variable will be kept at runtime. In contrast, the value stored
in a variable at runtime (its r-value) is not known until runtime. If the value stored in a variable is
required, the compiler emits code to read the value from the given address and put it in a register.


The key point here is that the address of each symbol is known at compiletime. So if the compiler
needs to do something with an address (add an offset to it, perhaps), it can do that directly and does
not need to plant code to retrieve the address first. In contrast, the current value of a pointer must be
retrieved at runtime before it can be dereferenced (made part of a further look-up). Diagram A shows
an array reference.


Figure A. A Subscripted Array Reference

That's why you can equally write extern char a[]; as well as extern char a[100];.


Both declarations indicate that a is an array, namely a memory location where the characters in the
array can be found. The compiler doesn't need to know how long the array is in total, as it merely
generates address offsets from the start. To get a character from the array, you simply add the


subscript to the address that the symbol table shows a has, and get what's at that location.

Free download pdf