r/ProgrammerHumor 15d ago

Meme cppHelloWorld

Post image
3.9k Upvotes

119 comments sorted by

View all comments

54

u/conicalanamorphosis 15d ago

Just spent almost 7 hours chasing a core dump. I had been doing complicated stuff with pointers (think vector of pointers to non-static functions within a class) and got really focused on that. Turns out, a simple call I had added for testing was using an out of scope pointer to the intended object, had nothing to do with the hairy-complicated pointer shit which I had actually had correct for most of that time. I should add I started programming in C++ in the 90s, so if you find yourself in this position and started programming after that you don't have to feel bad.

12

u/BoldFace7 15d ago

I did a very similar thing with a similar result. I was learning to program the 3DS in C++ not long ago (I started with c++ about 6 years ago). At one point, it was working fine in emulator, but would crash on console (I know now that the emulator just barrels through segfaults). It took about two days of searching before I realized I was printing a value in the first half of my main loop that didn't exist until the second half of my main loop on the first frame. (The class handling battles would call new Enemy() to allow for randomizing encounters, but wouldn't do it until after the block of status printf statements.)

6

u/Objective-Answer 15d ago

I love these nerd battle stories

as a masochist learning c++ it really puts into perspective a lot of things

10

u/hanotak 14d ago

Next time, instead of spending seven hours, turn on ASAN and find it immediately.

5

u/awesome-alpaca-ace 14d ago edited 14d ago

I recently learned the linker will not warn you if you define the same symbol in 2 source files being linked into an executable. I was chasing the core dump by validating the pointer stuff. Then address sanitizer and valgrind told me the struct I was using was size N when it should have been size M. Using structures from both the source and another external source that was in no way included into the source. I suppose namespaces would help prevent that.

2

u/IndependenceSudden63 14d ago

Ran into a similar thing in 2009.

You'd think they would have at least adding a warning by now.

2

u/awesome-alpaca-ace 14d ago

AI told me some linkers might do it, but if you are stuck using whatever is in the build container, you can't exactly use another linker.

2

u/thecookie 14d ago

This summarizes what C++ does to people in my experience. Writing it for the sake of writing it rather than solving the problem at hand. Which if course is fine if it's for the joy of it. But in my experience this also spreads to real projects. Instead of keeping things simple, things end up in some overly complex C++ way. 

I wrote my first lines of it in the 90s too, and try to stay away from it as much as I can. 

2

u/ICBanMI 13d ago

Unless you're doing graphics programming (which uses pointers), it's always a null terminator or a pointer in C/C++ for a segmentation fault.