- Joined
- Jul 23, 2011
- Messages
- 1,586 (0.34/day)
- Location
- Kaunas, Lithuania
System Name | my box |
---|---|
Processor | AMD Ryzen 9 5950X |
Motherboard | ASRock Taichi x470 Ultimate |
Cooling | NZXT Kraken x72 |
Memory | 2×16GiB @ 3200MHz, some Corsair RGB led meme crap |
Video Card(s) | AMD [ASUS ROG STRIX] Radeon RX Vega64 [OC Edition] |
Storage | Samsung 970 Pro && 2× Seagate IronWolf Pro 4TB in Raid 1 |
Display(s) | Asus VG278H + Asus VH226H |
Case | Fractal Design Define R6 Black TG |
Audio Device(s) | Using optical S/PDIF output lol |
Power Supply | Corsair AX1200i |
Mouse | Razer Naga Epic |
Keyboard | Keychron Q1 |
Software | Funtoo Linux |
Benchmark Scores | 217634.24 BogoMIPS |
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?
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?