auto declarations

Jonathan M Davis jmdavisProg at gmx.com
Fri Jan 7 16:30:24 PST 2011


On Friday, January 07, 2011 13:32:42 Ellery Newcomer wrote:
> auto a = 1, b = null;
> 
> int a = 1, *b = null;
> 
> 
> The first is accepted by dmd, and it should result in typeof(a) == int
> and typeof(b) == void*. It is somewhat contradictory to the error
> message resulting from the second:
> 
> multiple declarations must have the same type, not int and int*
> 
> I am skeptical of dmd's permitting the first. Does anyone else see any
> utility in it? 

The second should definitely _not_ be allowed. * definitely goes with the type in 
D (as it should have in C), not the variable. So, the *b = null makes no sense.

However, I'm vere suprised that the first one succeeds. I think that it should be 
reported as a bug. All variables declared on the same line are supposed to have 
the same type.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list