const int vs. int const

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 15 14:10:45 PDT 2014


On Friday, 15 August 2014 at 18:23:47 UTC, Timon Gehr wrote:
> On 08/15/2014 07:18 PM, John wrote:
>>
>> btw, it works either way if I use auto
>>
>> auto const minWage = 11; //works
>> const auto minWage = 11; //works
>> ...
>
> auto does not serve any purpose here.
>
>> The same flexibility is missing when the actual type is used.
>
> In particular, auto is not a wild-card type in that example.
>
> const minWage = 11;

Yeah, aside from auto ref, auto is pretty much just a placeholder 
when you don't want to put the type. Arguably, it shouldn't be 
allowed when attributes like const or static are used, but it is 
unfortunately allowed and essentially ignored in those cases.

Much as it first seems like auto tells the compiler to infer the 
type, the reality of the matter is that the compiler will infer 
the type unless you tell it the type and that auto is just for 
the cases where you don't want to use attributes and you need to 
indicate that you're declaring a variable rather than doing an 
assignment.

- Jonathan M Davis


More information about the Digitalmars-d mailing list