GCC compilations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • camlost
    Sangband 1.x Maintainer
    • Apr 2007
    • 523

    GCC compilations

    Huh, I just debugged a problem that showed up depending on the compilation flags I set. For debugging, I don't compile for speed, and I compile with gcc (mingw32) with no flags. For release, I set -O3 for increased performance.

    It turns out the problem was due to failure to initialize variables; do compilation flags affect variable initialization? Or was this just random?
    a chunk of Bronze {These look tastier than they are. !E}
    3 blank Parchments (Vellum) {No french novels please.}
  • takkaria
    Veteran
    • Apr 2007
    • 1951

    #2
    Originally posted by camlost
    Huh, I just debugged a problem that showed up depending on the compilation flags I set. For debugging, I don't compile for speed, and I compile with gcc (mingw32) with no flags. For release, I set -O3 for increased performance.

    It turns out the problem was due to failure to initialize variables; do compilation flags affect variable initialization? Or was this just random?
    Higher levels of optimisation tend to create more compact code using cleverer reasoning about your code, so sometimes stuff like this happens where previously you were relying on some undefined behaviour and that behaviour changes. With enough warnings turned on this should be exceedingly rarre.
    takkaria whispers something about options. -more-

    Comment

    • camlost
      Sangband 1.x Maintainer
      • Apr 2007
      • 523

      #3
      Originally posted by takkaria
      Higher levels of optimisation tend to create more compact code using cleverer reasoning about your code, so sometimes stuff like this happens where previously you were relying on some undefined behaviour and that behaviour changes. With enough warnings turned on this should be exceedingly rarre.
      Fair enough. I usually fix a dozen or so of these errors when I get around to compiling on Linux. I should figure out why CodeBlocks is suppressing so many errors; it'd save me time in the long run.
      a chunk of Bronze {These look tastier than they are. !E}
      3 blank Parchments (Vellum) {No french novels please.}

      Comment

      • pav
        Administrator
        • Apr 2007
        • 793

        #4
        I'd suggest avoiding -O3 unless you do all the debugging with it (impractical). Certainly turn based text game does not need to worry about cpu performance. GCC is known to miscompile some otherwise perfectly valid C code with -O3, especially when output target is something else than i686/linux.

        In the rather large open source C-written project I participate on (FreeBSD) we settled with -O2 -fno-strict-alignment as practical highest possible level. Even achieving that required some changes in code. Hiighest safe optimization in GCC is -O.
        See the elves and everything! http://angband.oook.cz

        Comment

        • Magnate
          Angband Devteam member
          • May 2007
          • 5110

          #5
          Even the Linux kernel uses -O2 rather than -O3.
          "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

          Comment

          Working...
          😀
          😂
          🥰
          😘
          🤢
          😎
          😞
          😡
          👍
          👎