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

Robert Fraser fraserofthenight at gmail.coim
Mon Feb 18 07:18:18 PST 2008


Janice Caron Wrote:

> 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).

I _think_ he was trying to describe it from a logical, rather than implementation standpoint. Logically, x "refers" (using the English term, not the programming term, mind you) to 4. 4 can't be changed (you can't say 4 = 7), but x can be.



More information about the Digitalmars-d mailing list