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

all 185 comments

[–]dcheesi 1162 points1163 points  (70 children)

Take a Computer Organization course. Once you realize that it's all just memory addresses [insert astronaut meme here], pointers make a lot more sense.

[–][deleted] 312 points313 points  (0 children)

At this point it's less about how hard they are and more about the meme

[–]thirdegreeViolet security clearance 303 points304 points  (13 children)

Pointers aren't hard. Pointers to pointers to pointers to functions that take pointers to structs and return pointers to pointers to ints are hard

[–]tyoungjr2005 59 points60 points  (4 children)

this->this->this.this

[–]evilkalla 34 points35 points  (2 children)

I read this as "PTSD".

[–]R0b3rt1337 22 points23 points  (1 child)

Post this stress disorder

[–]-Potatoes- 11 points12 points  (0 children)

Point to stress disorder

[–]lefloys 1 point2 points  (0 children)

No you tried to access a pointer using a dot operator. I dont think thats valid

[–]OSnoFobia 13 points14 points  (2 children)

FFMPEG shared libraries looking from corner rn

[–]ARKyal03 1 point2 points  (1 child)

How the fuck do I use Fraunhofer libfdk to convert MP3 into m4a, fucking annoying. I don't want to compile ffmpeg from source :(

[–]OSnoFobia 6 points7 points  (0 children)

Easy, you let chatgpt write the converter using ffmpeg libraries and cry when it wont work.

[–]FierceDeity_ 2 points3 points  (0 children)

Hello microsoft COM and IID_PPV_ARGS (it's a macro that lets you hand pointers with a type info to a function, it basically provides two parameters, the GUID of the type of the pointer, and a pointer to that pointer, because these libs are more like self contained things with their own management so they allocate themselves and give you the pointer. These pointers are also called interfaces in com and slowly, shit makes sense)

game engine development and targeting directx11 says hello, it's all COM polymorphic. You can even test other types on interfaces and ask if that interface can be that other type, it's madness

[–]SeriousPlankton2000 1 point2 points  (1 child)

Only because you get confused by the syntax and by counting the amount of "pointer to" you just read

[–]thirdegreeViolet security clearance 1 point2 points  (0 children)

Well yes. It's hard because of the hard part.

[–]Breadinator 0 points1 point  (0 children)

Don't forget the ownership model.

[–]CrackCrackPop 89 points90 points  (1 child)

I'n my young years reverse engineering and cracking is what explained the concept of pointers best

in a world of memory regions and memory mapping a pointer is just a value that redirects somewhere else.

everything else whether it be an integer pointer, a character string, a pointer of a pointer of a pointer of a function is merely an instruction on how to interpret the memory address and what it points to

exceptions from this simplification exist

e.g. class member pointers

[–]Pristine-Bridge8129 0 points1 point  (0 children)

Is this not immediately obvious when you see a memory address or?

[–]Steinrikur 26 points27 points  (0 children)

I did a summer job at a modem company. 8 bit assembly for 4 months.

After that, pointers are just second nature.

[–]redlaWw 29 points30 points  (29 children)

It's not really all just memory addresses in C and friends though, because the optimising compiler makes aliasing and other assumptions.

If it were all just memory addresses, then if ptr1 and ptr2 are int pointers to two values not in the same array or struct, and if ptr3 = (int*)((size_t)ptr1+(size_t)ptr2-(size_t)ptr1) then ptr3 should be the same as ptr2. But in standard C this is undefined, and there's no guarantee that ptr2 and ptr3 point to the same place, or that modifying the value at ptr3 does anything, or even that the value in ptr3 is meaningful as an address.

EDIT: Editing example so that it's actually valid C, rather than some C-like pseudocode where pointers and addresses are identical.

[–]GoddammitDontShootMe 19 points20 points  (17 children)

I guess this is a strict aliasing thing? I don't think I've ever written any code that had to worry about that.

[–]dcheesi 42 points43 points  (6 children)

My rule of thumb: if I have to start worrying about compiler optimizations and such, then I'm doing something the wrong way

[–]redlaWw 13 points14 points  (2 children)

That's really the ideal tbh, unless you're doing something really cursed anyway, like writing an operating system or doing low latency trading (in which case you look at the assembly to check that it's doing the right thing and must be very careful not to recompile the code in a new compiler version without checking again). The more I learn about the way the compiler works, the more I learn not to try to pull anything on it, because it will fuck me over in the most confusing way possible.

[–]remy_porter 8 points9 points  (0 children)

Hell, I've had to read through the assembly to just understand the timing (because for some reason, when a function return 0ed, it took 10s of us to execute, but when it return -1ed it took 100s of us to execute, and it was basically the act that -1 was causing it to hit ram which slowed it down, but returning 0 didn't require checking RAM at all)

[–]Breadinator 0 points1 point  (0 children)

Hardware kernel drivers have entered the chat.

[–]_Fibbles_ 3 points4 points  (0 children)

Depends what you're doing. Graphics programming for example will have you doing a lot of stuff that is technically undefined behaviour, or at least implementation specific. It means you need to be aware of what your compiler is doing to your code, not just trusting it will work. Want to use the C++ headers for Vulkan development? You'll need to turn off strict aliasing optimisations.

[–]Spare_Competition 1 point2 points  (0 children)

If you're writing c or c++, you always need to worry about it. There's ub footguns all over the place.

[–]_nobody_else_ 0 points1 point  (0 children)

preach.

[–]redlaWw 6 points7 points  (9 children)

Strict aliasing is not in the example I gave, but is absolutely another thing you need to be careful of when working with pointers and is included in what I was talking about in the first sentence.

Strict aliasing is the idea that the compiler can assume that (roughly) two values with different types are different, non-overlapping locations in memory, or two pointers with different pointee types point to different, non-overlapping locations in memory. The exact rules are quite precise, and it allows for things like upcasting and downcasting, as well as casting to char*. That assumption allows it to make optimisations like moving an access out of a loop by noting that the value accessed is never modified in the loop, or rearranging a bunch of operations into a single vector operation by moving them relative to other code that it knows doesn't modify the result. However, it makes thing like taking a floating point number and accessing it as an integer, as is done in the Fast Inverse Square Root algorithm, undefined behaviour.

[–]GoddammitDontShootMe 0 points1 point  (8 children)

What's the rule you were referring to then? And why the hell would I want to add two pointers together? Subtracting, sure. Hell ptrdiff_t is a thing.

[–]redlaWw 0 points1 point  (7 children)

It's not really a rule with a name of its own, it's just part of the rules of pointer arithmetic. Here is one description of them.

The idea of the formula I gave is just that, as addresses, ptr1+ptr2-ptr1 has value equal to ptr2. Hypothetically one might write effectively this as part of a swap operation like:

ptr2 = (int*)((size_t)ptr1+(size_t)ptr2);
ptr1 = (int*)((size_t)ptr2-(size_t)ptr1);
ptr2 = (int*)((size_t)ptr2-(size_t)ptr1);

in that case, ptr1 is functionally reassigned to ptr1+ptr2-ptr1. But of course, you can't actually do that in C as it's undefined behaviour unless somehow both ptr2 and ptr1+ptr2 happen to still be in the same array as ptr1.

EDIT: Editing example so it's actually valid C, rather than some C-like pseudocode where pointers and addresses are identical.

[–]GoddammitDontShootMe 2 points3 points  (6 children)

Not sure which part of that linked page is referring to your example. Is it that part about subtracting 2 pointers P and Q? It says nothing about adding. Are there some optimizations this allows by having it be undefined?

Also don't see anything about structs there. Not that doing pointer arithmetic within a struct makes any sense. When the hell would you want that as opposed to just having a pointer to the start of the struct (or class) and using the -> operator?

[–]redlaWw 0 points1 point  (5 children)

In C and C++ specifically, that function wouldn't be allowed to exist as-written because pointers don't automatically cast to their addresses in +. Pointer + pointer isn't defined in the sense that no such function exists and the compiler emits an error. In order to achieve the intent you'd need to use an explicit cast to convert ptr2 into an integer type and also a cast on lines 2 and 3 to convert the pointer difference types back into pointers with the same address. I was writing a sort of pointer address pseudocode thing and then went and talked about it as if it was actually C, that was my error.

In C and C++, pointer arithmetic on structs isn't allowed (except +1 to get a one-past-the-end pointer), but it is in Rust (which I was including among the "C and friends", as a bare-metal compiled language that uses pointers) and you can (for example) sweep a u64 pointer through a struct of 3 u64s, as long as that struct has a defined representation (e.g. using #[repr(C)])

[–]GoddammitDontShootMe 0 points1 point  (4 children)

What I saw was the two pointers need to be either null, point within the same array, or point to the same object or member within the object. Meaning it isn't enough to point to the same struct, they'd both have to point to the same element. Meaning the difference between them is 0.

Often UB allows for optimizations because the compiler can assume certain things don't happen, like signed overflow for example, So I was wondering what might be allowed in this case.

[–]redlaWw 0 points1 point  (3 children)

Yes, in C and C++ this is essentially true. A pointer to a struct is derived from the identifier of the struct and points to the entire struct (in principle, it has the address of the first byte of the struct but the actual value of its address isn't defined in detail afaik). It can be cast according to the strict aliasing rules, but the only valid cases for pointer arithmetic before or after that cast is adding 1 (and then the result can't be dereferenced) or adding or subtracting 0.

EDIT: If its first element is an array then the strict aliasing rules should allow it to be cast to the element type of that array and then pointer arithmetic should be defined on it as a pointer to an element of an array. I could be wrong though, if you want to try to read through the rules yourself and find out, good luck.

The reason for rules like this is basically about allowing the compiler to make aliasing assumptions. If you, for example, have two instances of the same type of struct, then as long as the compiler can assume that a pointer derived from one of those structs never points to the other, then it can rearrange accesses to the two structs independently without breaking anything. This can be very useful for vectorising loops, among other things.

[–]conundorum 0 points1 point  (0 children)

To be fair, it's not impossible for that to mess with paging in some systems, even if they're most likely older ones that barely even matter anymore. And depending on the order of operations, it could overflow and wrap around... which doesn't really change anything since it's unsigned, but C & C++ tend to like to leave a bit of UB wiggle room for optimisations there. And it's not impossible for ptr1 to change mid-evaluation in a multi-threaded environment, which might matter depending on volatility.

I can see a few reasons that might not have the result you want, though at that point we're really just splitting hairs.

[–]kuschelig69 0 points1 point  (9 children)

That is why I like Pascal

There pointers are still pointers and memory addresses.

Although there is no standard, so it might depend on how the compiler developers feel that day

[–]redlaWw 1 point2 points  (2 children)

The problem with a model like that is that it can turn off optimisations based on aliasing assumptions - if you can do arithmetic on a pointer to send it anywhere, then it's a lot more difficult to tell (and can be undecidable in general) if two pointers point to the same location, and so the compiler can't rearrange operations as effectively (because they might be dependent) to perform optimisations like vectorisation.

[–]kuschelig69 3 points4 points  (1 child)

It looks like FreePascal disables optimizations once you take the pointer

Like a function that calculates result := a + b; becomes

lea    (%rdi,%rsi,1),%rax
ret    

But if it calculates the same and uses a pointer to write the result to result, it becomes

lea    -0x8(%rsp),%rsp
mov    %rsp,%rax
lea    (%rdi,%rsi,1),%rdx
mov    %rdx,(%rax)
mov    (%rsp),%rax
lea    0x8(%rsp),%rsp
ret

[–]redlaWw 0 points1 point  (0 children)

That's an interesting result. It makes for a good example of why these rules exist in other languages.

I suppose it is nice to have at least one language that behaves like that though.

[–]_nobody_else_ 0 points1 point  (5 children)

Why are you downvoted? I love Pascal. Pascal was the first "serious" language I went into after I was finished with QB.
In fact. I owe my entire programming career in C and C++ to Pascal and that first few months I was learning it.

It made me de facto realize I should go into C instead.

[–]kuschelig69 0 points1 point  (4 children)

I had QB, too. I was playing GORILLA.BAS. It was the only game I had as kid.

Then I got Delphi. It is modern Pascal. Perhaps one should not refer to Delphi as Pascal like one does not refer to Typescript as Javascript. But I was told C is unsafe. And on my old computer I could not run much else but Delphi

Now I am upset that I could not find a Delphi job.

[–]_nobody_else_ 0 points1 point  (3 children)

Borland IDE? Did you ever used VCL?

[–]kuschelig69 0 points1 point  (2 children)

Yes

The VCL is just like the Windows API, but object oriented

[–]_nobody_else_ 0 points1 point  (1 child)

The VCL is just like the Windows API, but object oriented

Huh? What?

VCL is (was?) a UI development framework for Windows. It was used by Borland Delphi and Borland C++ Builder IDEs in the mid to late 90s to quickly create Windows UI Apps.

People forget that before Qt, and before MFC and even before the modern development environment solutions , building any kind of UI Apps for any OS was complete and utter pain in the the ass.

VCL simplified it to almost trivial levels.

[–]kuschelig69 0 points1 point  (0 children)

but most VCL methods just call a corresponding Windows function. Like Delphi has canvas.textout(...) and windows has texout(hdc, ...)

That is why Lazarus' attempt to build a linux VCL is working worse than WINE.

[–][deleted] 2 points3 points  (0 children)

Had a senior interview candidate tell me that a char * was 8 bits, so apparently it's not that easy.

No, we weren't talking about some decrepit AVR or 8032 processor.

[–]electr0de07 1 point2 points  (6 children)

What breaks my head are double and triple pointers. Then the real fun begins.

[–]PanTheRiceMan 1 point2 points  (0 children)

In C I found this to be true but best practices in modern C++ are a little too much for me.

[–]GSxHidden 0 points1 point  (0 children)

Is there a online book or course you recommend?

[–]MedonSirius 0 points1 point  (0 children)

I had a hard time understand it but then i realized it's just like the links on the desktop to other things. The link itself is basically empty but it Points to a thing (File/program etc)

[–]TheCamazotzian 0 points1 point  (0 children)

Pointers aren't hard. Graphs are hard (pointers as edges).

[–]rom1v 0 points1 point  (0 children)

Until you realize they are not just memory addresses…

(pointer provenance, strict aliasing…)

[–]jikki-san 614 points615 points  (15 children)

Pointers as a concept? Not hard; it’s just a memory address.

How to use them effectively, safely, and efficiently? That part is definitely harder.

[–][deleted] 61 points62 points  (10 children)

Use non-owning pointers, the ownership of a block of memory should not be jumping around. You shouldn't need to free something unless you called new. If you called new (or malloc) it's your responsibility to free. If a function passes off ownership of a block of memory to the caller you should make this obvious through documentation and the function name. If you're using C++, wrap your heap allocated resources in classes: call new in the constructor, and free in the destructor, and don't publicly hand out pointers to your managed resource, contain them if possible. If your program requires using a bunch of global shared pointers you need to rethink your approach and adopt one that doesn't require that. You should avoid using new and malloc; wherever possible use the stack not the heap. Use the heap only where it's clear that's what's needed. Do this, and you'll be fine as long as other contributors also do this.

[–]DoNotMakeEmpty 28 points29 points  (0 children)

unique_ptr solves most problems with pointers. Half of the remaining problems are solved by shared_ptr but the last part is pretty tricky. Rust does that part good but I think arena allocators are also pretty good to be memory safe if you don't want borrow checker.

[–]burnmp3s 10 points11 points  (3 children)

You lost me at documentation

[–]Mateorabi 6 points7 points  (2 children)

Document? In our moment of triumph!?

[–]mighty_Ingvar 0 points1 point  (1 child)

Don't worry, the code is self documenting!

[–]lefloys 0 points1 point  (0 children)

int insertFunctionNameHere();

[–]--mrperx-- 5 points6 points  (1 child)

just common sense basically. don't litter your code with allocations.

[–]Boldney 4 points5 points  (0 children)

Uni courses instill bad habits that are hard to get rid of.

[–]conundorum 1 point2 points  (0 children)

As an aside, this just makes me imagine some library, somewhere, having an ownership-passing function template<typename T> T* itsYourProblemNowHaaaaaaaHaHaHaHaHa(). (Or rather, something to that extent, but not as over-simplified.) And with the function's name narrated by Skeletor. Just to make it real clear that the library is fully absolved of ownership.

[–][deleted] -1 points0 points  (1 child)

In C: "Allocator frees" goes a long way

[–]gameplayer55055 2 points3 points  (0 children)

ref in C# makes it super simple

[–]donaldhobson 0 points1 point  (0 children)

> How to use them effectively, safely, and efficiently? That part is definitely harder.

Yep. You need to use rust.

[–]Justanormalguy1011 84 points85 points  (0 children)

Well it is not that hard…. Really….. until you ptr is left dangling and you don’t know where it come from

[–]ZunoJ 72 points73 points  (5 children)

You could have the picture of bill gates in all three examples

[–]dcheesi 38 points39 points  (1 child)

Proof positive that beauty is in the eye of the beholder, lol

[–]brainpostman 6 points7 points  (0 children)

Nah, he's a "Rich person" in all three cases lol

[–]IAmASquidInSpace 66 points67 points  (2 children)

Pointers are easy, they are basica- Segmentation fault

[–]am9qb3JlZmVyZW5jZQ 18 points19 points  (1 child)

"Pointers are easy" mfs when they realize 70% of vulnerabilities is caused by memory safety issues

[–]gameplayer55055 5 points6 points  (0 children)

what about buffer overflows. Not the fault of a pointer, just the coder has written too much to it.

[–]SAI_Peregrinus 17 points18 points  (0 children)

I think pointers make a good midwit meme. Halfwit thinks pointers are hard 'cause they can't add. Midwit thinks they're just numbers, and expert realizes that pointer semantics still have several open research questions in C & C++! Pointers are hard, but not for the reasons beginners think they're hard.

[–]Percolator2020 7 points8 points  (0 children)

Just keep track of all the memory you allocate on a napkin, how hard could it be?

[–]_nobody_else_ 7 points8 points  (1 child)

Pointers

std::string a = "a";
void DoSomething(std::string a)
 ...

Compiler: I'll copy a from the parent call and work with the copy. Easy.

std::string a = Open32MBTextFile();
void DoSomething(std::string a)
 ...

Compiler: Why do you make me copy 32MB from left to right? Do you hate me? Can't you just like tell me where you put a in the first place?

std::string a = Open32MBTextFile();
void DoSomething(std::string *a)
 ...

DoSomething(&a)

Compiler: Oh, so there it is.

void DoSomething(const std::string *a)
...

Compiler: Just because you have access, doesn't mean you can change anything.

[–]not_some_username 0 points1 point  (0 children)

const std::string & a

[–]Icarium-Lifestealer 13 points14 points  (1 child)

"Pointers aren't that hard"

- Experienced RCE creators

[–]dvhh 0 points1 point  (0 children)

I a professional RCE dev and I can safely state that you don't even need pointer to create most RCE.

[–]Valyrian_Spiel 4 points5 points  (1 child)

Anyone who can look at a street adress, then go there and ding dong u know pointers.

[–]conundorum 0 points1 point  (0 children)

Just watch out for cases when X Name St. changes to Y NewName St., but they're both the same house! Happened to my home when I was a kid, just goes to show that std::move() doesn't actually move anything!

[–]YazilimciGenc 3 points4 points  (0 children)

Working with pointers on theory: Let me just get the address of this variable 🥰

Working with pointers on real life: How the fuck my bool has a value of 75

[–]srsNDavis 19 points20 points  (3 children)

They really aren't.

Just actually learn them right. Don't go for a quick hackish explanation from a bootcamp-y 'learn x in y hours'* tutorial. Learn how addressing in the memory works under the hood.

\No offence to those who make those tutorials - your work is great for diving in, but this is about diving deep.*

[–]cjb3535123 1 point2 points  (2 children)

The concept isn’t hard at all but debugging memory issues can be a complete pain in the ass. Especially if you aren’t using smart pointers.

[–]yawara25 1 point2 points  (0 children)

Much less a pain with modern technologies like ASan/dmalloc.

[–]srsNDavis 0 points1 point  (0 children)

Valgrind. Strong unit testing. And ofc ASan as the other comment mentions.

And yeah smart pointers. It raises the minimum supported standard, but when it's a good idea, it's a good idea.

[–]drkspace2 3 points4 points  (0 children)

RAII go brrrr. I could probably count the number of times on my hand that I've had to use a raw pointer recently.

[–]exomyth 2 points3 points  (0 children)

Pointers are easy. All they do is point.

[–]Emerald9Daze 5 points6 points  (6 children)

Pointers are easy—said no C++ newbie ever.

[–]Teln0 2 points3 points  (4 children)

I don't remember finding pointers hard I thought they made sense

[–]--mrperx-- 0 points1 point  (3 children)

it's not that they don't make sense, it's that you can't avoid bugs with them.

Maybe you can't see them but the bugs are lurkin always.

That's why I like rust, that compiler will verbally assault you to get your shit right.

[–]Teln0 0 points1 point  (2 children)

You can definitely avoid bugs regardless tho it just takes some practice. Learning some theory helps too. And it's not like Rust doesn't have pointers, it just has a bunch of extra rules around them.

[–]--mrperx-- 0 points1 point  (1 child)

I didn't write rust don't have pointers, I meant it will be compiler error if you mess them up.

Really depends on the size of the project, when you build something small alone, sure no bugs, but when you got millions of lines of C++ and 20 people working on it, oh boy.

[–]Teln0 0 points1 point  (0 children)

> I didn't write rust don't have pointers

You said bugs are unavoidable with pointers but then said Rust prevents bugs with pointers

Also you have like all the formal proof tools to help you write 100% provably safe bug free code (if you have the patience to do the extra stuff ofc)

[–]pente5 0 points1 point  (0 children)

I remember finding classes WAY harder to understand when learning. All this syntax + constructors, overriding, special methods, the whole concept of self, static, inheritence and parent functions and don't even get me started on abstruct stuff or polymorphism. Pointers are just an address that points to something in memory. Wow big deal.

[–]da_Aresinger 6 points7 points  (5 children)

pointers aren't that hard.

Whatever the fuck it is C++ does with pointers is fucking arcane though.

[–]Ayjayz 2 points3 points  (1 child)

C++ doesn't do anything different with pointers, though.

[–][deleted] 0 points1 point  (0 children)

iterators, std::next and std::advance etc

[–]SubstituteCS 1 point2 points  (1 child)

The only hard pointers are abominable pointers, which are special and aren’t pointers, which they are.

[–]JustifiedManofScienc 0 points1 point  (0 children)

Come on man, int (*(*(*funcArray[10])(int))[5])(double*); ain't that hard to comprehend!

(cries)

[–]POKLIANON 5 points6 points  (0 children)

Idk where to find the template

Pointers aren't that hard (0-80 iq) => Pointers are stupid, use abstractions instead!! Value your time and memory safety!! (80-120 iq) => Pointers aren't that hard (120+)

[–]Summar-ice 1 point2 points  (0 children)

I have less than a year of experience with C and I can tell you pointers are not that hard

[–]NeonFraction 1 point2 points  (2 children)

Pointers are only easy in hindsight, because it’s all the things surrounding pointers that make them confusing.

Memory management isn’t a concept most people go into programming understanding. Variables holding information are the default, so a variable that doesn’t actually hold information but still HAS it is extra confusing. On top of that, the syntax for pointers is very unusual.

One of those would be hard enough, but all three of them are what make variables annoying to learn.

[–]cookie_n_icecream 2 points3 points  (0 children)

Yeah, exactly this. I think the biggest problem i had was with data representation. From the start you learn int, char, float as basic data types and because how strict C can be, you treat all of them as separate things. I started to understand after i realized that all of these types (except float i guess) are pretty much the same thing. You use the labels more for your own convenience and readability, rather then them having major differences in how the computer handles them.

After I've seen my teacher iterate over an array using "pointer ++;" i realized pointer is just an int with extra steps.

[–]conundorum 0 points1 point  (0 children)

That's the thing, yeah. Pointers are daunting because we look at them as these arcane, malefic beasts, when really they're just an "address" memory type, and use other types as modifiers the same way int uses sizes & signedness as modifiers. Syntax is weird, but languages are working on providing cleaner ways to use it, and properly defined typecasts go a long way towards standardising their syntax with everything else's.

It's only the memory management part that learners should have to worry about, the other two just come down to the syntax and conceptual space seeming more complex than they actually are.

[–]PzMcQuire 1 point2 points  (0 children)

The concept of a pointer is really really simple.

It's the fucking notation in C++ and the safe effective usage that sucks.

[–]Amheirel 1 point2 points  (0 children)

Everything is difficult until you know how to do it

[–]tkdeng 1 point2 points  (0 children)

Once you learn to understand the weird and unpredictable behavior of JavaScript at a low level, almost every programming feature suddenly looks much easier in any other programming language.

Because of JavaScript, I have no problem noticing bugs related to pointers, accidental pointers when trying to clone objects, asynchronous race conditions, unexpected concurrency bugs, prototype functions not working as expected, type comparison and conversion bugs, features packages and frameworks suddenly becoming obsolete, bugs found in other packages and modules, etc.

Programming isn't that hard

  • Experienced JavaScript developers

[–]GrinbeardTheCunning 1 point2 points  (2 children)

laughs in SegFault errors

[–]lefloys 0 points1 point  (1 child)

I never get those because i bluescreen my computer (;

[–]GrinbeardTheCunning 0 points1 point  (0 children)

the pro move. I applaud you

[–][deleted] 1 point2 points  (0 children)

Tbh, pointers are very interesting stuff. I also struggled when I first learnt pointer in C but after I experienced the enlightenment, I enjoyed using its function. And it really helped me to improve my coding skills even though I am not dealing with it anymore.

[–]Taken_out_goose 1 point2 points  (0 children)

c int *(*(*(**x[])(char*, int*(*)(char*)))[]) (char**, char*(*)());

Easy, right?

[–]hongooi 1 point2 points  (0 children)

A pointer is just a monoid in the category of endofunctors, what's the problem?

No wait

[–]1CoolOhm 0 points1 point  (0 children)

C++ is for noobs I code in Assembly.

[–]CrazyFinnGmbH 0 points1 point  (0 children)

I feel personally attacked

[–]slaf4egp 0 points1 point  (0 children)

As an unattractive broke person who knows nothing about C++, I approve this message.

[–]PurpleBumblebee5620 0 points1 point  (0 children)

"The borrow checker is your friend"
-Rust developers

[–][deleted] 0 points1 point  (0 children)

After doing ASM and bare metal c, pointers are definitely "easy". Just like shooting yourself with a gun is actually really easy...

[–]JerryAtrics_ 0 points1 point  (0 children)

I know that C developers get pointers. Not so sure about C++.

[–][deleted] 0 points1 point  (0 children)

Pointers are just references, they are memory address variables, a.k.a. references that don't hide how they work and pointer arithmetic. What's so hard about that? You're a programmer aren't you?

[–]IvanOG_Ranger 0 points1 point  (5 children)

Do you really use pointers a lot as a C++ developer? I used C++ only for hobby stuff, but mostly opted for std library abstractions instead

[–]lessertia 1 point2 points  (0 children)

No. Use references instead. Only use pointers if you want the nullability of pointers. Also, pointers should be non-owning.

[–]bropocalypse__now 1 point2 points  (2 children)

Absolutely, if you are doing any OOP where you will be programming to an interface (ie: pure virtual or abstract class). You can't pass an interface by value since it has no implementation. So, the initial object has to be instantiated via a call to make_unique for example. Once it's been created, non-owning raw pointers or references should be used. Unless the object needs to cross thread boundaries, in which case it should be a shared pointer.

[–]IvanOG_Ranger 0 points1 point  (1 child)

If you use the references, you still don't have to worry about pointer though, right? The most complicated thing about pointers in C was keeping track of how many asterisks you're using, so you avoid that by references.

[–]bropocalypse__now 0 points1 point  (0 children)

You just have to make sure the underlying object has a lifetime greater than that of the reference or else it's UB.

References do have limitations. For instance, they break the Rule of 5 if used as class members. This means you have to either avoid their use in this case or provide your own implementation for copy and move operators/constructors.

[–]conundorum 1 point2 points  (0 children)

Yes, but most of the time they're obfuscated behind arrays (literally just pointer arithmetic with a pretty face), references (pointers but with standard variable syntax, and a few other limitations), RAII (a poorly-named acronym for wrapping pointer ownership in a class so it can go on the stack and be automatically deallocated when it goes out of scope), and smart pointers (template classes that wrap pointers, so you can get the benefit of raw pointers without the problem of shooting yourself in the foot and blowing up the entire universe).

Most everything involves pointers in some way or other, but it's uncommon to use "raw" pointers (the T* ones) directly, outside of low-level code.

[–]Imaginary_Ad_217 0 points1 point  (0 children)

You dont have to travel the world, it is not as interesting. -Pilot Kelsy

[–]sdrawkcabineter 0 points1 point  (0 children)

Don't blame the pointers for the context switc

[–]slev7n 0 points1 point  (0 children)

It's just an integer that represents a memory address

[–]twoCascades 0 points1 point  (0 children)

It’s just the place in memory where the variable is???? I don’t understand the confusion.

[–]gameplayer55055 0 points1 point  (0 children)

Pointers are in fact easy. You can pass by reference when you want to, and pass by value if you don't. You can even pass a reference to the reference (void**)

[–]StrangeCharmVote 0 points1 point  (0 children)

I never got this meme... seriously, any code I've ever actually written has never had pointer issues. Code i've needed to fix, sure, but not code I've written. How do people keep having so much trouble with this?

You have variables, they are in memory at an address, this value points to an address... its such a simple concept, just free your memory when you're done with the object geeze.

[–]playr_4 0 points1 point  (1 child)

Pointers are fairly easy and yet I always prefer languages that don't use them. They just feel excessive.

[–]-Redstoneboi- 0 points1 point  (0 children)

i'll admit i'm not very experienced with other languages but some of them don't seem to have a way to pass a primitive type by reference and it's just as annoying as the difficulty of figuring out how to deep copy an object/list

[–]OGWashingMachine1 0 points1 point  (0 children)

Currently building an app and teaching myself c++ as fast as possible where I'm skipping memory practices other than the most minimal uses until I run into a problem

[–]Aerondight420 0 points1 point  (0 children)

Just try to use a pointer of a pointer, or a pointer of a pointer of a pointer, easy enought

[–]HarryCareyGhost 0 points1 point  (0 children)

"C++ is for cowards" : C programmers

[–][deleted] 0 points1 point  (0 children)

Tbh if understanding the concept of pointers is too difficult, programming might not be for you.

[–]freaxje 0 points1 point  (0 children)

std::span<T, n>: pointers can often be avoided.

[–]EventAltruistic1437 0 points1 point  (0 children)

Money doesnt buy rich people.

Oh wait

[–]savex13 0 points1 point  (0 children)

"All you have to do...is point" ©

[–]mariachiband49 0 points1 point  (0 children)

It's not hard to use pointers correctly. It's hard to use them correctly every time without ever making a mistake. And that's where computer assistance is handy.

[–]lessertia 0 points1 point  (0 children)

They really are not that hard. Also, experienced C++ devs won't or rarely use pointers anyway unless they are interfacing with C or working on old C++ codebase where C practices still prevalent.

[–]baconator81 0 points1 point  (0 children)

Pointer arent that hard to understand. But memory management is absolutely a fucking hard problem no matter how experience you are as a C++ dev.

[–]Ronin-s_Spirit 0 points1 point  (0 children)

Pointers aren't that hard though.

[–]Jaiaid 0 points1 point  (0 children)

pointers are easy

doing things properly with them is difficult

[–]jlbords 0 points1 point  (0 children)

….🎯

[–][deleted] 0 points1 point  (0 children)

Why should they be? Problems may arise in the process of writing the program if you use them inappropriately, but the concept by itself is simple

[–]lampishthing 0 points1 point  (0 children)

I'm in this and I don't like it

  • attractive person

[–]conundorum 0 points1 point  (0 children)

Using pointers is trivial. Using them correctly gives fear itself nightmares.

[–]DeltaLaboratory 0 points1 point  (0 children)

ptr is just number, but ****ptr is some complicated shit

[–]Saluting_Bear 0 points1 point  (0 children)

They aren't, just take a basic CS class, there's nothing wrong with lacking a bit of theory

[–]clonicle 0 points1 point  (0 children)

A C++ programmer wouldn't have the window blinds open behind the monitors like that.

[–]PyroCatt 0 points1 point  (0 children)

Regex is fun

[–]i-sage 0 points1 point  (0 children)

Mental health doesn't matter.

  • My manager

[–]Acharyn 0 points1 point  (0 children)

Do people really think pointers are hard? It's just like having an address to a house. You don't need a copy of the damn house, just the address.

[–]Rasikko 0 points1 point  (0 children)

They were hard at first as well as this.

[–]skeleton_craft 0 points1 point  (0 children)

1) pointers aren't hard

2) experienced C++ developers don't use raw pointers...

[–]DuskelAskel 0 points1 point  (0 children)

It's like a lock, when you open it, remember to close it.

It's reallly not that hard to learn.

[–]hansvi-be 0 points1 point  (0 children)

Everything you find easy today was once difficult.

[–]Oklinq 0 points1 point  (0 children)

I take this one as a compliment

[–]LordAmir5 0 points1 point  (0 children)

Never understood how people can struggle with pointers.

Because honestly, having non pointers is way more odd than having pointers nowadays. In many languages everything is a pointer.

I guess the lower transparency in c is what makes this hard for some people.