Does a better/newer C or C++ compiler produce more performant compiled code? Or do they just perform faster/better while compiling?

3

I am not a C or C++ programmer myself, but I often use software that needs to be compiled or otherwise depends on a compiler, like some R packages.

Will that software actually perform better if I use a newer/better compiler? For instance, right now I use the Mac OS X system version of Clang, and it's been suggested that I use a later version instead. Is that just a suggestion to save me time and memory during compilation? Or will it actually produce more efficient compiled software?

shadowtalker

Posted 2015-06-10T14:10:52.543

Reputation: 293

1For the person voting to close as "belongs on SO": this is not a development-related question; this is asking from a user's perspective (note: there are many OSes and software packages that expect the user to compile from source). It would be off-topic on SO, and is on-topic on SU; close reasons are far more nuanced than "he mentioned compiling!". – Bob – 2015-06-10T14:26:04.180

1@Bob thank you. I had actually written this on StackOverflow originally, and then decided to post it here instead – shadowtalker – 2015-06-10T14:26:51.380

@fixer1234 I've specifically added C and C++ to the title and tags – shadowtalker – 2015-06-10T15:13:56.197

@fixer1234 you're reading way too far into the question. If the answer is "there's no good answer" then so be it – shadowtalker – 2015-06-10T15:46:33.100

Answers

3

Will that software actually perform better if I use a newer/better compiler?

This entirely depends on if work is done to the code optimization feature, of the compiler, in a given release.

For instance, right now I use the Mac OS X system version of Clang, and it's been suggested that I use a later version instead.

You should stick with the same compiler version that you know works, unless you need a feature, that exists only in a later version. Unless you know a later version does something more effective you should not upgrade.

Is that just a suggestion to save me time and memory during compilation?

The suggestion honestly seems 100% opionion based. If you trust the person that provided this suggestion then you should take it.

I should point out that a compiler, is software, and newer versions can introduce new bugs which result in worst performance in the optimization routinue. You should seek a balance, the best way to do this, is always use the stable release build.

Ramhound

Posted 2015-06-10T14:10:52.543

Reputation: 28 517

Good answer, but would be useful to mention that while it's often a bad idea to upgrade out-of-band without good reason, you should still perform upgrades that are part of the official OS release. Also, sometimes newer compiler releases actually introduce regressions (they can do a worse job of optimising certain code than an older release). – Bob – 2015-06-10T14:30:23.940

What I see here is a tentative "no". Or "maybe, but probably not enough to matter and you might break something in the process." Accurate? – shadowtalker – 2015-06-10T14:32:14.637

@Ramhound: according to the question, the OP is doing the compiling. – fixer1234 – 2015-06-10T15:04:31.550

@Ramhound you have it backwards. I don't usually compile my own code (R is an interpreted language; I use Python as well), but I am occasionally required to build add-on packages from source, which must be compiled before I can use them. I do also use a program called Stan for which I do need to compile C++ code, albeit automatically generated C++ code. – shadowtalker – 2015-06-10T15:13:04.247

@Ramhound: I have problems with the question, but your answer is good. +1 – fixer1234 – 2015-06-10T15:39:58.547