Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
sinisas3237yPointers are the best thing ever invented in the history of programming:)
Just to clarify: are you ranting about your coworkers that have problems with it, or about difficulty to understand how it works? -
As I've explained multiple times (and people replied that it's a very easy way to understand):
Variables are always just names that we temporarily give to storage cells (imagine a set of P.O. Boxes or Pack Stations or square grid). You can either put stuff in these cells, or look what's in there, by knowing the temporary name assigned to them.
Put:
a=2
See:
print(a)
Now a variable is a permanent name to that cell actually.
A pointer is basically when you have a variable, and you look at what's in that cell, and it's the name of another cell, where the actual stuff that you need sits.
You can keep the stuff in their original cells, but just change the label inside the pointer cell, and it will suddenly point to a different cell. And 2 cells can have a label inside that could point to exactly the same cell, so when you say Cell1->pointerCell->get, it will be the same as Cell2->pointerCell->get.
So a pointer is basically an additional level of addressing memory. -
malloc - yeah you basically tell the post office that you need one, two, three P.O. Boxes next to each other, and the post office tries to make that happen.
Bit shifting is completely different topic. Represent a number in binary (done using base conversion). Bit shifting literally does what it says - shifts bits. Shifting them to the left means adding more zeroes at the end. Shifting them to the right means removing the last bits.
It's like you get the *10 and /10 in decimal, but it's all in binary, so it's actually *2 and /2 instead. -
rui7257607yDo you guys have other topics which can help me understand more and be more familiar with at least an intermediate level as embedded developer.
-
D--M22667yI remember learning pointers..
Didn't get a fucking thing UNTIL one day I was working on an RTS game and thought to myself; "it sure would be nice if i could change what this variable pointed to"
Tldr; one day you will have that moment and you'll think pointers are the greatest thing ever. -
If you learn binary math and the basics of how computers work, these are some of the easiest concepts there are.
-
rui7257607y@sinisas wow I seriously thank you for giving a code that explains the process of pointers :)
-
Orionss28867yReally, it's not that difficult, you just have to take the time to understand well what happens when you use them but after, it's like natural
-
I remember my first malloc for a 2 dimensional array in C... Took me 2 days to figure out what the fuck was going on in the StackOverflow code snippets I found 😆
-
Mmh...hard if you have no background in computer architecture.
Study the CPU first and how it deals with memory , then come back and tell us if it's difficult anymore. -
rui7257607y@bdhobare I think I know some stuff about computer architecture from logic gates to scheduling algorithm.. but I just dont know how does it relate to embedded dev
@iSwimInTheC I think they have that covered using List or Collections..but to use the memory address as a reference value I dont think that it is possible in other language
@StefanH agreed but yea I also liked to learn how are these relate to embedded dev or game dev.. just picturing the bigger picture would help understand why they exist..
Why is pointers... bit shifting.. malloc.. anything that is regarding embedded development is so hard to grasp...
question