It doesn't. Constness is an additional relevant information for type
resolution and const correctness that is processed at compile time.
Additionnaly, the compiler may use the const qualification to put static
data into a RO area of the objet bytecode or to perform optimisations
but that's all.
Actually, the compiler *could* differentiate. If the address of
the variable is never taken, or if the compiler could establish
that the function cannot be called recursively (e.g. if it was a
leaf function), then the compiler could put the variable in the
text segment as well.
More generally, the compiler will differentiate when optimizing;
it will exploit its knowledge of the fact that the value is
known and cannot be changed. Thus, for example, if you write:
extern void g( int const& ) ;
int
f()
{
int const i = 42 ;
g( i ) ;
return 3 * i ;
}
, the compiler will probably generate the last statement as if
you'd written "return 126;". Without the const, it can't
(unless it can see into the body of g, and assert that g doesn't
cast away const and modify the value); it must read the actual
value and multiply it by 3.