Are there compiler options in Visual Studio 2010 to provide portable C ++ writing?

I get C ++ source code from a developer who compiles using Visual Studio 2010, which I then need to recompile in different different compilers: GCC, LLVM, other versions of Visual Studio, etc. Sometimes the code that it sends to me (which compiles without warning in VS2010) cannot be compiled under other compilers.

Are there any compiler settings that it can set in VS2010 to increase the likelihood that its code will be fully portable?

+8
c ++ portability visual-studio visual-studio-2010 compiler-errors
source share
1 answer

There is no silver bullet at the tongue level. The best you can do is stick to your locale as close as possible. Most compilers have options for issuing warnings or errors if you use an extension specific to a particular compiler (with Visual C ++, /Za will disable non-standard language extensions). But this is not ideal, since no compiler implements absolutely 100% of the standard, so you can still have portability problems even with strictly compatible code.

Also keep in mind that a lot of everyday code really takes advantage of the extensions, or undefined - or the behavior defined by the compiler, often without implementing it, so it would be impractical to compile it in completely standard mode.

You should also know that standards allow you to be different. For example, types such as int can be of different sizes for different systems. Windows is LLP64, while most Unix-based OSs are LP64.

At the system level, I don’t know the ideal way to make sure that the programmer does not rely on something specific to the system (for example, <windows.h> or <pthreads.h> ).

It’s best to do everything so that developers can run test builds on all target platforms.

+3
source share

All Articles