Greetings fellow programmers! xD Ok, ./serious_mode Recently I came across a strange thing: code I wrote was working fine, but as soon as I decided to make a non-debug build (has compiler optimizations on), I noticed a strange thing - my program promptly segfaulted each time I ran it. If I rebuild it with compiler optimizations off, it then works fine again. That was a little shocking to me. I then searched the web (which was mostly confined to reading stuff on stackoverflow.com). I found out that others have also encountered this. Some with long time programming experience encountered this many times and sometimes even expect this to happen sooner or later with growing projects. Though, pretty much every instance I found people mentioning this, were just small sidenotes to some discussions involving compiler optimizations, thus, not discussed any more deeper than that. So I would like to ask You all to share Your thoughts on such a thing - "how, why, when, etc." And I mean, in general sense. Not just about this specific case I encountered. One of my thoughts - compiler optimizations, AFAIK, according to standard (at least on C & C++) state that it should not alter the a program works in a way that would produce different results compared to a non-optimized one. That it normally does - makes sure it runs the same. If the program does run and behave differently (like my previously mentioned segfault), I think it is not automatically a compiler's fault. If one were to write his/her code in such a way that confuses the compiler, it could accidentally make the program behave in an unintended way. Thus, I wonder, if a person produces code that is handled by the compiler this way, could it be an indication that the said person's coding style is not good and/or that this person is writing his/her code in such a way that would make any experienced hacker frown?