Why compiling your code in GCC is a good idea.

Sometimes Microsoft’s C++ compiler just produces bad binaries.

At the moment I’m working on code that compiles just fine using the Microsoft C++ Win32 & Xbox 360 compilers. However it does not run. It crashes during static initialization deep inside the C runtime library. It crashes hard well before the debugger can even load the debug symbols so I don’t even know in where it might be dying. It crashed the Xbox 360 so hard it crashed the IDE.

This is no fun to debug.

GCC on the other hand won’t even compile my code. I’ve been a very bad boy in many spots without even thinking about it and the Microsoft C++ compiler hasn’t complained. At all. Not one little bit. I’ve even got warnings cranked all the way up.

Now after running GCC over my code until it is satisfied that I’ve been a good boy, I compile my code again with Visual C++. This produces a working executable and I can get on with my job.



5 thoughts on “Why compiling your code in GCC is a good idea.

  1. At least part of the problem here is that even with compiler warnings turned to Level 4 in Visual C++, there are still a number of warnings which are disabled by default, see: http://msdn.microsoft.com/en-us/library/23k5d385(VS.80).aspx

    It’s something I spoke to Cam about fixing when he first arrived at IRG. I’m not sure if enabling these warnings would have given you better insight into the issue you were having, but there are some warnings that really make you think “Why the hell isn’t THAT enabled by default?”

    Another thing I spoke to Cam about was the possibility of introducing some flavour of lint to catch those things that compiler warnings just don’t catch. Not sure if he’s looked any further into that but it might be a good idea to bug him about it.

    Still, I agree with your original conclusion regardless of all this. Testing (or even just building) your code on multiple compilers can be of great benefit to you as a programmer… particularly if your primary compiler is Visual C++. =)

  2. There is a kind of live-fast-die-young aspect to many Microsoft products.

    I like to think that the personality of the company producing the code gets embodied in the code to some degree.

    Many of Microsofts products does don’t seem well suited to doing things in a way that is sustainable in the long term. I think this is a side effect of their aggressive approach to attempting to win in markets.

    Nice to hear GCC solved your problems, I’ve had a soft spot for it since university when I could use the same GCC version on Solaris, Tru64 Unix and Linux, and happily change my location of work at will 🙂

    (I think it was )

  3. Sounds to me like the solution to this is a GCC plugin into the MS dev environment that compiles the code with -Wall, tosses the binary and shows you the warnings.

  4. Is there something like that available for MinGW or similar? I know this is how the PS2/PSP/PS3 compilers work with the SN Systems compilers for these platforms, which is what I’m assuming you did, Oliver.

    Failing that, how hard is it to convert a Visual Studio solution into a Makefile? I’ve never quite been able to get my head around those blasted things.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s