auto storage class - infer or RAII?
Walter Bright
newshound at digitalmars.com
Sun Nov 12 02:24:35 PST 2006
Sean Kelly wrote:
> Walter Bright wrote:
>> The auto storage class currently is a little fuzzy in meaning, it can
>> mean "infer the type" and/or "destruct at end of scope".
>
> As Don explained to me, 'auto' is a storage class in D and in C along
> with 'const' and 'static', so type inference doesn't occur because
> 'auto' is present so much as because a type is omitted. The presence of
> 'auto' merely serves to indicate that the statement is a declaration
> (since 'auto' is the default storage class and therefore otherwise
> optional). Type inference occurs with the other storage classes as
> well. I think this is an important distinction because it seems to be a
> common misconception that 'auto' means 'infer the type of this
> expression' and that a specific label is necessary for this feature.
True. Consider that type inference works in these cases:
static a = 3; // a is an int
const b = '3'; // b is a char
So auto doesn't actually ever mean "infer the type", it's just needed
because one of the other storage class keywords isn't there.
More information about the Digitalmars-d
mailing list