Objects
An object is a specific region of memory that can hold a fixed or variable value (or set of values). This use of a term object is different from the same term, used in object-oriented languages, which is more general. Our definiton of the word would encompass functions, variables, symbolic constants, user-defined data types, and labels.
Each value has an associated name and type (also known as a data type). The name is used to access the object and can be a simple identifier or complex expression that uniquely refers the object.
Objects and Declarations
Declarations establish a necessary mapping between identifiers and objects. Each declaration associates an identifier with a data type.
Associating identifiers with objects requires each identifier to have at least two attributes: storage class and type (sometimes referred to as data type). The mikroC PRO for 8051 compiler deduces these attributes from implicit or explicit declarations in the source code.
Usually, only the type is explicitly specified and the storage class specifier assumes the automatic value auto
.
Generally speaking, an identifier cannot be legally used in a program before its declaration point in the source code. Legal exceptions to this rule (known as forward references) are labels, calls to undeclared functions, and struct or union tags.
The range of objects that can be declared includes:
- Variables
- Functions
- Types
- Arrays of other types
- Structure, union, and enumeration tags
- Structure members
- Union members
- Enumeration constants
- Statement labels
- Preprocessor macros
The recursive nature of the declarator syntax allows complex declarators. You’ll probably want to use typedefs to improve legibility if constructing complex objects.
Lvalues
Lvalue is an object locator: an expression that designates an object. An example of lvalue expression is *P
, where P
is any expression evaluating to a non-null pointer. A modifiable lvalue is an identifier or expression that relates to an object that can be accessed and legally changed in memory. A const pointer to a constant, for example, is not a modifiable lvalue. A pointer to a constant can be changed (but its dereferenced value cannot).
Historically, l
stood for “left”, meaning that lvalue could legally stand on the left (the receiving end) of an assignment statement. Now only modifiable lvalues can legally stand to the left of an assignment operator. For example, if a
and b
are nonconstant integer identifiers with properly allocated memory storage, they are both modifiable lvalues, and assignments such as a = 1
and b = a + b
are legal.
Rvalues
The expression a + b
is not lvalue: a + b = a
is illegal because the expression on the left is not related to an object. Such expressions are sometimes called rvalues (short for right values).
What do you think about this topic ? Send us feedback!