Page 1 of 1

C99 mode

Posted: Fri Jan 18, 2013 5:25 am
by BMW
When I tried to use a for(int i=0;i<2000;i++) in my kernel, it says for-loop initial declaration is only allowed in C99 mode.

Should I use C99 mode for kernel development?

Re: C99 mode

Posted: Fri Jan 18, 2013 5:56 am
by iansjack
I just stick with the default and don't declare variables in the loop initialiser. No big deal.

Re: C99 mode

Posted: Fri Jan 18, 2013 7:13 am
by bluemoon
I'm using c99 switch, not because of for-loop initialization but just stick to a "recent" and stable standard (compare to c90).

Re: C99 mode

Posted: Fri Jan 18, 2013 7:27 am
by Love4Boobies
Why would you recmmend using a version of the C language that is 24 years old, as if C wasn't a bad language already? If you really must use it, you should be rely on its most recent version (i.e., C11, although note that most compilers don't fully implement it yet). Languages, just like software, evolve for two reasons: (a) bugs, and (b) their requirements change (which is an obvious thing to happen as new technology, methodologies, and techniques develop or old ones improve). The only reason to use C89 is to compile old, C89 code.

As to why C89 is the default mode of GCC, which is probably the compiler you are using, it's so that it won't break compatibility with old build systems which expect C89 because that's the only thing that existed back when the projects they are part of were written... After all, you can't break forwards compatibility.

Re: C99 mode

Posted: Fri Jan 18, 2013 2:56 pm
by BMW
bluemoon wrote:I'm using c99 switch, not because of for-loop initialization but just stick to a "recent" and stable standard (compare to c90).
Ok thats what I'll do.

Thanks.