Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Mixed declaration and code" warning, is it worth addressing?

I've recently enabled -pedantic option on gcc and now I've got about two or three pages of "ISO C90 forbids mixed declaration and code" warnings.

My goal with this project is to be able to deploy it on any mainstream system with a c compiler, so I realize it wouldn't be wise to assume that C99 will be supported everywhere, but is it even worth my time to address these warnings?

Are there still systems out there with c compilers that don't support mixed declaration and code?

like image 888
Graphics Noob Avatar asked Dec 29 '09 17:12

Graphics Noob


2 Answers

Well, was/is it your intent to write your code in C89/90 or in C99?

Since this is the only warning you seem to be concerned about, apparently your code was actually written in C89/90. If it is indeed so and you plan to stick with C89/90, then I'd stick to strict C89/90 and move all declarations to the beginning of the block.

If, on the other hand, you are willing and planning to switch to C99, then "misplaced" declarations are no longer an issue. Then your main concern becomes the platform/compiler support. MS Visual Studio C compilers are C89/90 compilers. Is this a problem? (Considering that GCC is available on Windows platforms).

like image 183
AnT Avatar answered Sep 24 '22 06:09

AnT


If you want to be -pedantic about the C99 standard add the option -std=c99.

Personally I like the older unmixed style because it makes it easier to audit visually what types of memory the function is using and decide what might need free()-ing before returning.

like image 40
mlibby Avatar answered Sep 21 '22 06:09

mlibby