You don't have to group variable declarations all at the beginning of a block, as we used to do in C. (I believe that was because they needed to be allocated on the stack by the compiler.) Declare variables when you're about to use them.
Just a little bit of bean counting: C99 allows to declare variables where you need them. Today's C compilers have become smart enough. Here's a silly example:
/tmp>cat c99.c #include <stdio.h> #include <string.h> int main(int argc, char ** argv) { char buf1[10]; snprintf(buf1,sizeof(buf1),"%d",argc); int n=0; for (int i=0; i<argc; i++) { int len=strlen(argv[i]); len++; n+=len; } char buf2[10]; snprintf(buf2,sizeof(buf2),"%d",n); char buf3[80]; snprintf(buf3,sizeof(buf3),"%s args using %s bytes",buf1,buf2) +; puts(buf3); return 0; } /tmp>CFLAGS="-std=c99 -pedantic -Wall" make c99 cc -std=c99 -pedantic -Wall c99.c -o c99 /tmp>./c99 foo bar baz 4 args using 18 bytes /tmp>
Alexander
In reply to Re^2: OO method wont parse
by afoken
in thread OO method wont parse
by jorba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |