Why can't we define re-assignable const reference variable?

Janice Caron caron800 at googlemail.com
Mon Feb 18 04:23:46 PST 2008


On 18/02/2008, Sergey Gromov <snake.scaly at gmail.com> wrote:
> One can safely assume that a variable x of type int with a value 4 in it
> is a mutable reference to an object 4 of type invariant(int).

Not unless you've redefined the word reference.

At the ABI level, a reference is identical to a pointer. It occupies
four bytes of space (eight on a 64 bit machine), and those four bytes
contain an address. The difference between a reference and a pointer
occurs at the syntax level, not the ABI level.

What you've described there is not a reference at all - it's an int. A
reference to an int would occupy eight bytes of memory (four for the
reference, and four more for the int).



More information about the Digitalmars-d mailing list