What are Objects
In C, there are two types of objects:
- Elemental: declared explicitly -
int x
,int* xp
,float A[10]
,node_t node
- Have identifiers as their names (
x
,xp
,A
,node
) - May have either a basic or a derived type, type specification can surround name
- Have identifiers as their names (
- Compound: constructed implicitly - dereference
xp
, index toA
, access a component ofnode
- Has a tree structured name combining identifiers, constants, and accessors (
*xp
,A[6]
,node.children
,node.children[0]
,node.children[*xp]
) - May have either a basic or derived type:
int
,float
,(node_t*)[3]
,node_t*
- Type is inferred by a post order traversal of the tree
- Has a tree structured name combining identifiers, constants, and accessors (
Helper Methods
For a C object named x
, define:
TYPE(x)
to be the C language type ofx
ADDR(x)
to be the lowest numbered memory byte occupied byx
at runtime (&x
)SIZE(x)
to be the number of memory bytes occupied byx
at runtime (sizeof(x)
)BOX(x) = [ADDR(x), ADDR(x)+SIZE(x)-1]
, the range of memory bytes holding the machine representation ofx
VAL(x)
to be the value ofx
, obtained by applying the type-specific interpretation to the machine representation ofx