2

Does C dialect affect optimization in gcc? That is (all optimization options being held the same) will gcc produce faster/slower/larger/smaller code for ANSI vs C99 vs ...?

Underhill
  • 408
  • 2
  • 13
  • 1
    I can think of at least one case off the top of my head where it could: [Are compilers allowed to eliminate infinite loops?](http://stackoverflow.com/q/2178115/1708801) – Shafik Yaghmour Jun 17 '15 at 19:35
  • 1
    @ShafikYaghmour But it doesn't mean GCC will actually eliminate them, even if allowed.. – Eugene Sh. Jun 17 '15 at 19:37
  • @EugeneSh. it does not, I did say *could* – Shafik Yaghmour Jun 17 '15 at 19:38
  • @Shafik OK ... but I was looking for something more real-world-ish that might actually affect my code. – Underhill Jun 17 '15 at 19:56
  • @ShafikYaghmour: "... controlling expression is not a constant expression ...". `1` _is_, a _constant expression_. I really would wonder if a compiler would remove such a loop. It may, however, optimize-out any expressions inside the loop if thier side-effects are not used externally. That would be, normal optimizations. – too honest for this site Jun 17 '15 at 19:58

1 Answers1

3

It could, likely.

One difference between C89 ("ANSI C") and C99 is the restrict keyword added with C99, which is specifically geared towards improving optimization. While your code may not explicitly use it (because you wrote C89 code), the C language headers like <string.h> may declare function prototypes using restrict when in C99 mode. This may or may not have an effect. You'll only know when you look at the generated code.

Jens
  • 69,818
  • 15
  • 125
  • 179