previous | start | next

Example 1

    1   int sumFirst(int n)
    2   {
    3     int ans = 0;
    4     int i;
    5     for(i = 1; i <= n; i++) {
    6         ans += i;
    7     }
    8     return ans;
    9   }

In default settings for the gcc C compiler, for loops can't declare loop variables. That is, a compile error is generated for:

      for(int i = 1; i <= n; i++) {
   

This should be valid in the new C standard (C99), but many compilers only partially implement C99 including gcc.

So the gcc compiler default is the earlier standard.

The partial C99 features implemented by gcc are used when the option -std=c99 is present.



previous | start | next