One thing one needs to keep in mind about the storage is the as-if rule. The compiler is not required to put a variable in a specific place - instead it can place it wherever it pleases for as long as the compiled program behaves as if it were run in the abstract C machine according to the rules of the abstract C machine. This applies to all storage durations. For example:
42
in the generated assembly code but no sign of 404
.const
or effectively const
need not be in memory. Example - the compiler can prove that foo
is effectively const
and inlines its use into the code. bar
has external linkage and the compiler cannot prove that it would not be changed outside the current module, hence it is not inlined.malloc
need not reside in memory allocated from heap! Example - notice how the code does not have a call to malloc
and neither is the value 42 ever stored in memory, it is kept in a register!malloc
and the reference is lost without deallocating the object with free
need not leak memory...malloc
need not be within the heap below the program break (sbrk(0)
) on Unixen...