'in' storage class
    Funog 
    funog at ifrance.com
       
    Wed Sep  5 11:40:49 PDT 2007
    
    
  
Nathan Reed Wrote:
> Funog wrote:
> > 'in' is equivalent to final const scope.
> > I can't understand the point of making the variable 'final' if it's already 'const' ?
> > 
> 
> In D 2.0, 'final' represents 'head-const', while 'const' means 
> 'tail-const'.  This makes a difference when talking about arrays: 
> 'final' will make the array reference itself const, so you can't change 
> it to refer to a different array, while 'const' makes the contents of 
> the array const - you can change the variable to point to another array 
> or slice, but you can't edit any array through that reference.
> 
> Thanks,
> Nathan Reed
It's true for const(uint[]) or const(uint)[], but we are talking of const uint[], which forbid any change.
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' ?
    
    
More information about the Digitalmars-d-learn
mailing list