15 Apr
2003
15 Apr
'03
03:05
On Tue, 2003-04-15 at 04:46, Derek Fountain wrote:
if(i==5) { int z=i; printf("%d\n", z); } }
It's always a good idea to declare a variable as close as possible to the place it's used.
Beware though that this was banned in C89, so a strictly conforming compiler would barf on it. I think it's legal again in C99.
Readers of your code then won't need to go paging up so far to find the variable type or initialisation.
Two comments, first you shouldn't have procedures so long that you have to go paging up to find the start of it. And second, to my mind it's much better to have all declarations in one place. If, 50 lines later you see variable z used, where will you look for its declaration?