Question

So I'm working on this C/C++ library, and I'm using the GNU compiler, which supports the latest standard of C and C++.

I want to make my library compatible with the VC++ compiler which only supports C89/C90, not the newer C standards that allow variable declarations after other statements inside of a function body.

Is there a tool I can use that will make all my variable declarations at the beginning of the function bodies?

My library is quite large and having a tool to do this task will make the process easy.

Was it helpful?

Solution

Sorry for the anti-answer, but Visual C++ is not a C compiler. It may be a compiler for some old, outdated (22 years outdated, to be precise) language, which is not C. The best thing you should do is to advise people that are asking you for such support about this and request them to switch compiler and not use a broken one.

If this solution is really beyond your choice (it's not), then there are similar topics that you could look for: How to compile c99-to-c89 convertor with clang? https://github.com/libav/c99-to-c89/

If you think what I said makes no sense think again: It's a 22 year outdated C compiler. Think about the effort and money that people all over the world have spent to support it.

Edit: btw, that's C: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

http://www.open-std.org/jtc1/sc22/wg14/www/standards

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top