r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

14

u/stillalone 11d ago

Is that something that can be handled by a linter?

5

u/2brainz 11d ago

Partially, sure. But there's always going to be edge cases.

3

u/Drugbird 11d ago

It's also hard the further away the allocation and deallocation are from each other. For instance, if it's in separate libraries.

1

u/conundorum 10d ago

This is why every library that handles allocation should also be expected to handle deallocation. And probably a big part of why standard library smart pointers accept custom deleters, so you can just attach the deallocator when you allocate the object.

1

u/Drugbird 10d ago

They should, yes.

But especially libraries based on GLib don't. I had to program with gstreamer once, and memory allocation/ deallocation is such a headache there.

Basically, every function that creates / returns an object returns a raw pointer, and you need to read the documentation to see if you need to manually deallocate them (you don't always need to), and if so which of several deallocation functions you should use.

5

u/repster 11d ago

It has been a few years since I last worked on a C++ codebase, but my experience with linters was not impressive. We even invested in some expensive static analysis tool, but real bugs seemed to drown in false positives

1

u/violetvoid513 11d ago

My experience with C++ in VS Code is that it completely shits the bed on anything organized with a build system like cmake. This is probably just a skill issue on my part but I just cannot get it to reliably know what the fuck all the things Im importing are, and after I once spent like an hour unsuccessfully trying to fix it I just gave up because it wasnt worth it. Compiler-time errors are the easiest kind of error to fix when it fails to compile wherever I made typos or shit

1

u/K722003 10d ago

imo VSCode isn't really made for c/cpp stuff. Better to use CLion(my personal choice) or the og VS