The 2024 Wheel Reinvention Jam is in 16 days. September 23-29, 2024. More info

Satisfying multiple compilers - worthwhile?

I'm currently compiling some code I initially wrote under MSVC using GCC/G++ on linux. Even without -Wall/-Wextra, I get several new warnings and in some case, errors from code which compiled silently under MSVC. So far, I've been able to satisfy both compilers with the same source.

I thought it would be best to try and be as 'correct' as possible for as many environments as possible, but I'm wondering if this could turn into a fools errand. Am I going to run into places where 'fixing' things for one compiler make it impossible to get a warning-free build from the other, and just end up with a game of whackamole?
My recommendation, is do whatever is easiest for you currently... If you are actively using both GCC and MSVC, or if you intend for others to be able to use those compilers, then you should probably do as much as you can to make that seamless (including supporting clang). But I am much lazier than that, if I am using the code on windows, then i'll fix the issues as I go there, if I happen to be using the code on Linux, then I'll fix the issues there... Either way, you shouldn't have to be playing too much Whackamole... make sure you are using the same C/C++ std all around, ( --std=c++11 ?)

Edited by David Butler on
Makes sense, thanks.
This piece from IT Hare has some very good advice on fighting compiler warnings. See Example 3 in particular.
I've usually found that when starting a new project there is a bit of friction between different compilers and -Wall/-Wextra warning settings. A few days of development will show probably 98% of the cases you need to worry about (i.e. disable over zealous warnings) for both compilers. Once done that, development becomes a lot smoother.

When I was working with multiple OSes (Windows + Linux) I usually developed under Linux (better compile and iteration times, way worse debugging experience however) and then compiled and tested under Windows. GCC and Clang raise more warnings than MSVC and their error messages are better to parse, so it made sense for me. However, YMMV. :)
I have worked on pretty big C++ codebase on Windows, Linux, OSX (not a game though). We compiled with "-Wall -Wextra -Werror" for GCC for Linux and Clang for OSX. And /W4 with few warnings disabled on MSVC. Initially it is kind of annoying, but you quickly learn what are most common warnings and don't make these mistakes anymore, and that helped a lot to have code almost always working on other OS'es than you are writing for. Sometimes compiler warnings on other compilers actually caught real bugs (usually it was clang showing warnings for things MSVC ignored).

So in my experience - yes, it is worthwhile.
Thanks for all the feedback. I like the idea of having as many warnings on as possible and I'm already finding what people have said, which is that you find a large percentage of all relevant warnings up front.