'in' storage class

Funog funog at ifrance.com
Thu Sep 6 10:02:16 PDT 2007


Robert Fraser Wrote:

> Funog Wrote:
> 
> > Nathan Reed Wrote:
> > 
> > > Funog wrote:
> > > > void testFinal(final int[] foo)
> > > > {
> > > >     foo[0] = 10;        //OK
> > > >     foo = new int[20];  //ERROR
> > > > }
> > > > void testConst(const int[] foo)
> > > > {
> > > >     foo[0] = 10;        //ERROR
> > > >     foo = new int[20];  //ERROR
> > > > }
> > > > void testFinalConst(final const int[] foo)
> > > > {
> > > >     foo[0] = 10;        //ERROR
> > > >     foo = new int[20];  //ERROR
> > > > }
> > > > 
> > > > 
> > > > So what is the difference between 'const' and 'final const' ?
> > > > 
> > > 
> > > I suppose there's no practical difference in that case since you're 
> > > using the transitive const.  Note that final const(int)[] foo is 
> > > different from const(int)[] foo though.
> > > 
> > > Thanks,
> > > Nathan Reed
> > 
> > 
> > 
> > I agree... But then, what is the point of having 'in' equivalent to 'final const scope' rather than just 'const scope' ?
> > 
> 
> The difference is easier for me to grasp when talking about class references than arrays.
> 
> class Foo { int bar; }
> 
> final Foo baz;
> baz.bar = 5; // Okay
> baz = quux; // Illegal
> 
> const Foo quux; // Equivilent, I _think_ to const(Foo) quux;
> quux.bar = 5; // Illegal
> quux = baz; //Okay
> 


It isn't... Both lines are illegal. quux = baz is legal for const(Foo) quux.
If nobody can tell the difference between "const scope" and "in" ( = final const scope ), should we report it as a bug ? xD



More information about the Digitalmars-d-learn mailing list