auto storage class - infer or RAII?
Kristian Kilpi
kjkilpi at gmail.com
Sun Nov 12 06:44:51 PST 2006
On Sun, 12 Nov 2006 12:24:35 +0200, Walter Bright
<newshound at digitalmars.com> wrote:
> 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.
So according to this logic, auto should always mean RAII?
E.g.
auto c = new Class; //RAII
If not, then one could argue that
static a = 3;
declares non-static variable, i.e. the static keyword is used for type
inference only (whenever the type is omited).
More information about the Digitalmars-d
mailing list