On Tue, Jun 23, 2009 at 12:32:05PM +0200, Stefan Reinauer wrote:
stephan.guilloux@free.fr wrote:
Hello all,
To start teh day, a small patch for an invalid local variable... In C, local variable must be declared before any statment, and not, like in C++ in the middle of the function.
Thanks a lot for the patch!
The restriction of local variable declarations only working at the top of the function has been revised in the C99 standard. Every compiler that is C99 compliant will understand the code and do the right thing.
Stefan
I personally dislike this, as it is only done to make it easier for people to be lazy.
By being forced to declare variables at the beginning of blocks, people are pushed towards creating smaller blocks and therefor expose natural deliniations quicker. Then people are more likely to create small (inlined) functions out of those blocks instead of using {} in the middle of a block.
Just because the compiler can handle it doesn't mean that you should write less good code than you could.
Let's keep variable declarations old style, as it is a style choice which has some consequences with respect to human behaviour.
Luc Verhaegen, A very lazy man who knows what he would be doing if things were made too easy on him.