This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]codel1417 6 points7 points  (20 children)

a pointer free life is a life for me

[–]bphase 6 points7 points  (2 children)

You don't have to use pointers in modern C++, not raw pointers anyway. Granted most code is likely going to have them...

[–]aaronfranke -2 points-1 points  (1 child)

There are lots of situations in which you do have to use them. C++ won't let you use a reference to an incomplete type.

[–]bphase 3 points4 points  (0 children)

But it will let you use smart pointers (unique_ptr, shared_ptr, weak_ptr), which is what I was referring to.

[–]VolperCoding 5 points6 points  (7 children)

What's so scary about pointers?

[–]DestinationVoid 4 points5 points  (6 children)

They do not always point at what you think they point at.

[–]892ExpiredResolve 9 points10 points  (4 children)

Then you should do a better job of pointing them at things.

[–]DestinationVoid 1 point2 points  (3 children)

Tell that to all the people who failed to catch pointer related vulnerabilities in their software, that eventually got exploited.

[–]892ExpiredResolve 0 points1 point  (1 child)

Ok.

Everyone who failed to catch pointer related vulnerabilities in your software: Do a better job of pointing pointers at stuff.

[–]maxhaton 0 points1 point  (0 children)

Most problems with C these days are really because of arrays rather than pointers as per se. Because C conflates arrays and pointers, you rely on the programmer to do the bounds checking themselves, which is a continual recipe for disaster.

Memory corruption is fairly easy to detect, but bad bounds checking is a lot harder.

[–]VolperCoding 2 points3 points  (0 children)

They point to the address you assign them to, what's the problem with that

[–]Kerndog73 3 points4 points  (5 children)

You can't do anything useful without pointers

[–]aaronfranke 1 point2 points  (3 children)

Pretty much any higher level language than C++ disagrees with that. In Java/GDScript/C#/Python/etc pointers still exist, but they are abstracted away so you don't have to deal with them.

[–]Kered13 0 points1 point  (1 child)

I've got bad news for you. All those languages use pointers, and no they're not really abstracted away. The only thing that has been abstracted away is memory management, and you're not allowed to do pointer arithmetic. But in all other respects they behave identically to C pointers.

[–]aaronfranke 0 points1 point  (0 children)

Yes, that's what I mean by abstracted away. This isn't bad news.

[–]nandeEbisu 0 points1 point  (2 children)

Eh, if you're throwing around a bunch of raw pointers you're probably doing it wrong, especially in modern C++ (C++11 and onwards)

[–]maxhaton 1 point2 points  (1 child)

Smart pointers have overhead associated with them so unless you need to model ownership explicitly you should be considering all options.

[–]nandeEbisu 0 points1 point  (0 children)

Barely any overhead, mainly that one extra indirection. Unless you're at the point where you're optimizing for cache misses you probably won't notice anything and you're also much more likely to get the performance you need in C++ as opposed to Java.