What is the difference between...

Daniel Keep daniel.keep.lists at gmail.com
Fri Sep 7 04:57:59 PDT 2007


IIRC...

Janice Caron wrote:
> Even more simply put, what is the difference between:
> 
> (1) void f(const int x)

That's const as a storage class: the bits of 'x' are immutable.

> (2) void f(const(int) x)

const as a type constructor: in this case, nothing happens since
const(T) only has an effect on reference types.  Let's change it to

> (2) void f(const(int*) x)

Ok, now you've got a mutable read-only view: the bits of 'x' can be
changed, but the data referenced by x cannot.

> (3) void f(const const(int) x)

*rubs out previous line*

> (3) void f(const const(int*) x)

I suspect the const(int*) is redundant.  Since const is transitive,
const as a storage class automatically applies const-ness to the type as
well.

> Just trying to get my head around this!

	-- Daniel



More information about the Digitalmars-d mailing list