Saturday, January 31, 2009

C99 vs. C90

In playing with the source code coming with the book "Modeling with Data" on my Ubuntu box, I discovered one thing: code looks like this:

...
for (int i = 0; i < N; i ++) {
...
}
...

does not work with the default gcc command line options and issues error message of "Error: 'for' loop initial declaration used outside c99 mode".

The way to fix is either to change the code to:

...
int i;
...
for (i = 0; i < N; i ++) {
...
}
...

or put a "-std=c99" in the command line switch and do nothing with the source code.

No comments:

Counter