Different types with auto

Jonathan M Davis jmdavisProg at gmx.com
Thu Mar 17 13:53:25 PDT 2011


On Thursday, March 17, 2011 13:17:33 Jason E. Aten wrote:
> > auto x1=1., x2=2., x3=3., x4=4., x5=5, x6=6.;
> 
> If the coder wanted them to all be doubles, it's easy to require that by
> just saying so, and then even x5 will be a double.
> 
> double x1=1., x2=2, ...
> 
> So it seems to me that auto does exactly what you asked it to here, and I
> actually prefer this behavior for conciseness and expressiveness sake.

Personally, I hate it when variables are declared no the same line period, and I 
find the fact that auto allows you to have multiple variables on the same line to 
be inconsistent with other declarations. Just because auto infers the type 
doesn't mean that they variables being declared with it shouldn't all have the 
same type. I was _very_ surprised when I learned that auto allowed you to 
declare different types of variables on the same line, and I think that it's 
definitely bad. But since pretty much the only time that I ever declare multiple 
variables on the same line is before the condition of a for loop, it's not like 
it's causing me any grief either way. And if I react negatively to it in code, 
I'm already reacting negatively to someone having declared multiple variables on 
the same line anyway.

- Jonathan M Davis


More information about the Digitalmars-d mailing list