I receive C++ source code from a developer who is compiling using Visual Studio 2010, that I then need to recompile under various different compilers: GCC, LLVM, other versions of Visual Studio, etc. Sometimes the code that he sends me (that compiles without warnings in VS2010) fails to compile under the other compilers.
Are there any compiler settings he can set in VS2010 to increase the likelihood that his code will be cleanly portable?
Microsoft C++ Compiler (MSVC) This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.
The Visual Studio build tools include a C compiler that you can use to create everything from basic console programs to full Windows Desktop applications, mobile apps, and more.
After writing the code, right-click on the program, as shown below. Click on the Run Code option or press Ctrl + Alt + N from the button.
In Visual Studio You can set compiler options for each project in its Visual Studio Property Pages dialog box. In the left pane, select Configuration Properties, C/C++ and then choose the compiler option category.
At the language level, there is no silver bullet. The best you can do is to stick to the language standard as closely as possible. Most compilers have options to issue warnings or errors if you take advantage of an extension that's specific to a particular compiler (with Visual C++, /Za
will disable non-standard language extensions). But this isn't perfect, as no compiler yet implements absolutely 100% of the standard, so you can still have portability problems even with strictly-compliant code.
Also be aware that lots of everyday code actually takes advantage of extensions or undefined- or compiler-defined behaviors, often without realizing it, so it might not be practical to compile in a fully standards-compliant mode.
You also have to be aware of things that the standards allow to be different. For example, types like int may be different sizes on different systems. Windows is LLP64, while most Unix-derived OSes are LP64.
At the system level, I don't know of a perfect way to make sure a programmer is not relying on something system-specific (e.g., <windows.h>
or <pthreads.h>
).
Your best bet is to make it simple for all developers to run test builds on all target platforms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With