Handmade Hero » Forums » Code » Satisfying multiple compilers - worthwhile?
Twicetimes
9 posts

None

#7862 Satisfying multiple compilers - worthwhile?
1 year, 4 months ago

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?

None
Croepha
David Butler
66 posts
1 project

I love pretty much anything technical, whether it be programming, networking, hacking or electronics.

#7863 Satisfying multiple compilers - worthwhile?
1 year, 4 months ago Edited by David Butler on Aug. 5, 2016, 7:20 p.m.

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 ?)

404 Signature not found
Twicetimes
9 posts

None

#7894 Satisfying multiple compilers - worthwhile?
1 year, 4 months ago

Makes sense, thanks.

None
Pseudonym
Andrew Bromage
174 posts
1 project
(tbd)
#7940 Satisfying multiple compilers - worthwhile?
1 year, 4 months ago

This piece from IT Hare has some very good advice on fighting compiler warnings. See Example 3 in particular.

sub f{($f)[email protected]_;print"$f(q{$f});";}f(q{sub f{($f)[email protected]_;print"$f(q{$f});";}f});
marcc
Marc Costa
23 posts
#7951 Satisfying multiple compilers - worthwhile?
1 year, 4 months ago

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. :)
mmozeiko
Mārtiņš Možeiko
1517 posts
1 project
#7952 Satisfying multiple compilers - worthwhile?
1 year, 4 months ago

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.
Twicetimes
9 posts

None

#7973 Satisfying multiple compilers - worthwhile?
1 year, 4 months ago

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.

None