Re: [Patch] tty: move a definition out of switch block

From: Cong Wang
Date: Tue Dec 08 2009 - 05:08:06 EST


Alan Cox wrote:
jumps to its first label at a first glance. I know in this case
the code is _not_ wrong, but again, it's not good for reading.

So this is just your personal preference ? That seems like pointless
churn, especially given that many other people consider putting the
variables there is better than

case foo:
{
Blah blah
}
}
}

in switches

Well, in C99 6.5.4, it has a very good example to explain this.
See this example:

switch (xxx) {
int a = 1; //<-- not initialized
int b; //<-- seems to be skipped, but not
func(&a); //<-- skipped;
case 1:
//...
break;
case 2:
return a; //<-- uninitialized value;
}


So why not just:

int a = 1, b;
switch (xxx) {
case 1:
// blah blah
}

? A first galance will know everything, no need to guess if
'switch' skips it or not.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/