Tuesday, April 5, 2005

C99

While writing C-code, I frequently needed some local variable to temporarily store some value or create arrays with size fixed at runtime (not using malloc). The dirty workaround I used was the scope trick.

void f() {
int b,c;
/* large code segment */

{
int temp = somefunction(b);
/* avoiding calling somefuntion multiple times */
c = (temp > 0 ? temp : anotherfunction(temp));
}
}


Recently I was debugging some code where I saw a variable declaration in the middle of a scope (illegal in C89) but compiling perfectly with gcc3.4. That led me to C99. C99 has a lot of improvements - making life a lot easier for the programmers. For more, check the standards or look here. Just a side note, gcc 3.x supports C99 to some extent. To see the difference between the two standards, compile using gcc -std=c89 -pedantic file.c.

- d.

No comments:

Post a Comment