7

I wanted to update my previous rant in the comment but what happened is such a fucking nonsense I think it deserves its own.

For those who don't want to look what it is, just another C++ noob (aka me) complaining about how the language was a bitch to him by throwing a random SEGFAULT on release while it didn't show up on debug. Welp.

Half an hour and a ton of std::cout later (thought I would try to read a disassembly ? Think again) I figured out what was the problematic section of code. And guess what ? It was a section I didn't even modify and I never had problems with. Something completely unrelated to what I was rightly imagining causing the issue.

To identify which exact subsection was throwing the error to my face I added more tag code.
Rubbing my hands and ready to fix the fuck out of this damn shit, I built it, launched it…

And all of a sudden the code worked.

All I did. Was to add more cout to know which line fucked up. And now it works.

So. Serious question now: is it a clear sign from heaven I should stop working with such languages and should go back in my shitty high level languages kindergarten ?

Comments
  • 7
    Classic Heisenbug - the introduction of additional debug code shifts the memory layout so that something else gets overwritten which is not critical.

    I'd advise using command line GDB like this: http://unknownroad.com/rtfm/gdbtut/...
  • 1
    @Fast-Nop This relieves me to know what happened is not something out of nowhere — though strange
    I'm checking this right now, thank you !
  • 0
    @Fast-Nop Just tried it out, but it's the same problem I adressed with my IDE: it is telling me the faulty ASM line, but not my code's. What would you suggest ?
  • 0
    @CodeTalker Did you compile with debug info? With GCC, that would be -g. Usually, GDB can do source level debugging.
  • 1
    @Fast-Nop I'm trying to compile by hand, but g++ is being a pain and doesn't seem to recognize filesystem since it is not a namespace name for it. It will be more painful than expected

    I theoretically could let my IDE do the job by putting it in debug build mode. Problem is, no error happens here. Reason why I'm even wondering if compiling with g++ -g is useful since it will give same results
  • 3
    @CodeTalker Take a look at the compiler flags the IDE uses for debug/release, they shouldn't be hard to find. If release is on -O3 you got your problem, take it back to 2. -O2 and below shouldn't be dangerous. Ensure that you didn't do something that's officially undefined behavior like making assumptions about struct sizes and member positions past what sizeof and the member offset operator return.
  • 0
    If you wanna go low level, use C or Rust. C++ is really just a huge pile of shit at this point... No wonder Linus strongly prefers C over C++ for his kernel.
  • 1
    @CodeTalker If you're under Linux, you could also try GCC's sanitiser features: https://gcc.gnu.org/onlinedocs/gcc/...

    Next would be static code analysis, CppCheck is available for free: http://cppcheck.sourceforge.net//... (Windows), under Linux als CLI tool from the package manager, maybe there are even graphic frontends.

    If you are dealing with an open source project whose codebase is public, the cloud-based Coverity Scan is available for free, with clients for Linux and Windows: https://scan.coverity.com/

    Clang with -Weverything will flood you with warnings, but if the project is small enough, even that might be tolerable. GCC's -Wall and -Wextra are also there, but I think you already tried that.
  • 1
    @Lor-inc @Fast-Nop I will check all of that
    Thank you a lot !
  • 0
    @aggelalex No it fucking isn't. C++ is used in many large projects and remains popular despite all of its flaws. Stop driving away newbies by pretending that time tested and popular languages suck. If he was experienced in low level stuff and we had a clear use case you could start a meaningful debate on the relative merits of rust to c++ with respect to the specific problem.
Add Comment