Difference betwee storage class and type (invariant/const)?

Robert Fraser fraserofthenight at gmail.com
Mon Jun 18 12:52:45 PDT 2007


Ah, I see, thanks! So the difference is mainly when it applies to a naturally-reference type such as an object?

"const(Foo) bar" only the data inside the object is const, while with "const Foo bar", both the data and the reference are constant?

Kirk McDonald Wrote:

> Robert Fraser wrote:
> > Can someone explain to me what the difference is between a storage class and a type is, with regards to const and invariant? For example, what do these do differently?
> > 
> > invariant int foo;
> > invariant(int) foo;
> > 
> > ...? I know this is probably second-nature to people with C++ backgrounds, but I find the documentation quite confusing, as I've only really worked in Java before.
> 
> Between those? Nothing. The difference is here:
> 
> invariant int* foo;
> invariant(int)* bar;
> 
> The former is equivalent to:
> invariant(int*) foo;
> 
> That is, when it is used as a storage class, it applies to the whole type.
> 
> -- 
> Kirk McDonald
> http://kirkmcdonald.blogspot.com
> Pyd: Connecting D and Python
> http://pyd.dsource.org



More information about the Digitalmars-d-learn mailing list