Warning iso c90 forbids mixed declarations and code - pedantic




















Johan Kotlinski Johan Kotlinski Johan Kotlinski But why does this matter? Add a comment. So, you will need to do the following: Determine if your compiler supports C99 or later; if it does, configure it so that it's compiling C99 instead of C89; If your compiler doesn't support C99 or later, you will either need to find a different compiler that does support it, or rewrite your code so that all declarations come before any statements within the block. John Bode John Bode k 17 17 gold badges silver badges bronze badges.

This answer is incomplete at best. It does fix the problem but doesn't explain what caused it. This answer excludes situations where a newer compiler isn't possible several possible reasons A down vote because I can't agree this is the "real" answer.

Ron Nuni Ron Nuni 1, 1 1 gold badge 19 19 silver badges 14 14 bronze badges. You can still initialize the variable, you just can't place code before you declare it.

If the OP could clarify the context, then a more directed response would follow. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.

Email Required, but never shown. The Overflow Blog. Connect and share knowledge within a single location that is structured and easy to search. 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? If, on the other hand, you are willing and planning to switch to C99, then "misplaced" declarations are no longer an issue. Is this a problem? Considering that GCC is available on Windows platforms. 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.

The Visual Studio C-compiler does not allow mixing declarations and code. Microsoft will probably never add full C99 support to Visual Studio; C is not important enough in the Windows world. However, if you do decide you want to, it's pretty easy so maybe you should ; Just have all your declarations right after beginning a code block.

If you absolutly must define them later, use another nested code block. I would eliminate that particular warning as intermixing code and declarations is not a widely supported feature. Actually I have the same problem with a library I'm writing.

I'm using variadic macros but those seem to be more supported. To ensure my library will be really usable by others, I'm going to test it with as much compilers I can. Unfortunately SourceForge no longer provides a compilers farm as it used to do some years ago and I can't test it on commercial Unix compilers.

I couldn't even see the image, just a text placeholder. My employer's proxy blocks the image hosting site. Note that the name of the gcc option that disables this warning is even more descriptive than the text of the warning itself: -Wdeclaration-after-statement.

It is complaining that at least one of your declarations appears after one or more executable statements. This is allowed in C99 and later, but was forbidden in C Two options: tell your compiler to accept C99 it's been 18 years, you really should upgrade , or move all your declarations to the top of the function: it's your int i that's the problem.

Move it to the top of the function. Show 2 more comments. Active Oldest Votes. Improve this answer. Add a comment. The Overflow Blog.



0コメント

  • 1000 / 1000