Programming thread

  • 🔧 Chat is under maintenance.
    🧊 New server is in an office waiting on a mexican.
  • Want to keep track of this thread?
    Accounts can bookmark posts, watch threads for updates, and jump back to where you stopped reading.
    Create account
So i've been learning cpp (and c too!) but when we get to memory management i can't manage to figure shit out. I've been recommended by a friend to try to get some experience in rust cause the languages are basically the same but with a borrow checker so that when i do get the time to figure out memory management i can actually have some idea of what is to be written. not sure if this is the right thing to do since i've heard both good things about the cpp vs rust debate and just got told that as long as you don't interact with the communities, both are pretty good languages
What exactly you don't understand about memory management? Ask your questions, we don't bite.

I'd recommend first learning it in C, and then moving up to C++ if you need to. C++ has way more features like 'placement new', which may confuse a novice. It also revolves around classes and constructors which makes it more difficult.
 
This is embarassing to admit, i've never really understood pointers and going through the C bible never really cleared it up; are there any written guides which help with it?
Along with that, i can't for the life of me manage to separate the differences between a stack and heap,
pointers literally just hold the address of something else. Dereferencing is just going to that address. You are probably thinking about it being something more complex than that.

And yhe difference between stack and heap is mostly that the stack holds all values passed into a function (a pointer holds a memory address which is a value too) and any variables declared within the function. Anything that can be trqced to a malloc is on the heap
 
pointers literally just hold the address of something else. Dereferencing is just going to that address. You are probably thinking about it being something more complex than that.

And yhe difference between stack and heap is mostly that the stack holds all values passed into a function (a pointer holds a memory address which is a value too) and any variables declared within the function. Anything that can be trqced to a malloc is on the heap
To help you remember which controls what when allocating memory: S and C in stack are system and computer, H and P in heap are human and programmer respectively.
 
So i've been learning cpp (and c too!) but when we get to memory management i can't manage to figure shit out.
It's practically pointless to learn how to manage memory at such a low-level, especially as a beginner. It's easier to use an assembler language than to use the C or C++ languages for this kind of educational work, because at least the assembler language isn't going to hide anything. Why hide the stack, in effect, but not the heap? Also, calling it the heap is stupid; most machines don't distinguish between stacks and other types of memory anyway. Ironically, those that distinguish this are also generally the type to handle a lot more in hardware.
 
Anything like the TIS-100 game that'd do that or should i dive headfirst into a 6502 simulator?
Just use an emulated C64, geez.
<pedantic>The C64 is not the 6502, it's a 6510, it's a 6502 with an 8 bit GPIO port that the C64 used for bank switching ROM and IO in and out of memory space as well as the datacassette.</pedantic>
 
So i've been learning cpp (and c too!) but when we get to memory management i can't manage to figure shit out. I've been recommended by a friend to try to get some experience in rust cause the languages are basically the same but with a borrow checker so that when i do get the time to figure out memory management i can actually have some idea of what is to be written. not sure if this is the right thing to do since i've heard both good things about the cpp vs rust debate and just got told that as long as you don't interact with the communities, both are pretty good languages
C, specifically C99, but newer standards are OK, is (one of) the great aryan man's programming languages. Rust is a nulang that has a plethora of issues alongside being infested with the most insufferable people of gender around. C++ can either be alright or horrifically niggerlicious depending on what features you use (ironically, the less "C++-esque" the code is, the better it will be)

Just stick with it. If your hands are white or yellow you can learn memory management and you can be good at it. Maybe step back a little and look at the broader picture, if you learn how computers in general handle memory it makes it really easy to understand why/how to do it in C. Same goes for a bunch of other concepts you'll run into. Also, C has the benefit of literal decades of autistGODs sperging over it; there's bound to be an insanely in-depth writeup hosted on some dude's personal blog or even on an old BBS archive
C's pointer syntax is, for some reason, exceptional, and is the ONLY reason why pointers are hard to think about.
It's pretty gay but if you learn the equally gay way of reading it it's not so bad https://c-faq.com/decl/spiral.anderson.html
 
Also, C has the benefit of literal decades of autistGODs sperging over it; there's bound to be an insanely in-depth writeup hosted on some dude's personal blog or even on an old BBS archive
So amusingly, the exceptional individuals working on the musl libc—because copyleft is yucky—fucked up SSH:

I'll look around to see what others have been saying about this here, but I'm to understand their implementation of the crypt() function is to blame for this unacceptable faux pas. Now, of course, the idea of storing passwords and other account information in /etc/shadow and using an asterisk to indicate accounts without valid passwords is asinine to anyone who's used a real type system. These exceptional designs pop up constantly with C language programming because it's so piss poor, and expressing a proper solution is harder than being really, really careful with a shittier system until someone fucks it up anyway. Part of the problem, of course, is how these systems become an undocumented and tangled mass where every part touches every other part.
 
Can I just say: Fuck doubly linked lists. Some of the weirdest and most subtle bugs ever. And not even easy to debug (I forgot to update the pointer linking back from the next element upon inserting, 2-3 hrs to track it down until I broke down and asked a clanker)
What do people actually use these for btw? I've never encountered a use case where any kind of linked list was the best choice.
 
This is embarassing to admit, i've never really understood pointers and going through the C bible never really cleared it up; are there any written guides which help with it?
Along with that, i can't for the life of me manage to separate the differences between a stack and heap,
Do you understand indexes? If you understand indexes, you understand pointers. They are indexes to your memory basically.
If you go lower level it's a bit easier, because there is none of this type bullshit - just addresses.

I highly recommend a book called 'Programming from the Ground Up'. It teaches the essential bits of assembly programming in x86_32 using gnu assembler. Seriously, read it, you'll gain a lot of knowledge.
I used this book when first learning assembly, and even though I am not a native english speaker, I got it all. It's a very easy and enjoyable read. No bullshit, just good explanations.

Speaking of books and bullshit - I fucking hate Tanenbaum books. I probably have said it already, but fuck this wealthy roody-poo. He just can't explain things succinclty. It's always a lot of words and unfunny jokes.
 
Last edited:
C, specifically C99, but newer standards are OK, is (one of) the great aryan man's programming languages. Rust is a nulang that has a plethora of issues alongside being infested with the most insufferable people of gender around. C++ can either be alright or horrifically niggerlicious depending on what features you use (ironically, the less "C++-esque" the code is, the better it will be)

Just stick with it. If your hands are white or yellow you can learn memory management and you can be good at it. Maybe step back a little and look at the broader picture, if you learn how computers in general handle memory it makes it really easy to understand why/how to do it in C. Same goes for a bunch of other concepts you'll run into. Also, C has the benefit of literal decades of autistGODs sperging over it; there's bound to be an insanely in-depth writeup hosted on some dude's personal blog or even on an old BBS archive

It's pretty gay but if you learn the equally gay way of reading it it's not so bad https://c-faq.com/decl/spiral.anderson.html
What the fuck. Genuinely what the fuck do you mean i gotta go around in spirals to parse C??

Do you understand indexes? If you understand indexes, you understand pointers. They are indexes to your memory basically.
If you go lower level it's a bit easier, because there is none of this type bullshit - just addresses.

I highly recommend a book called 'Programming from the Ground Up'. It teaches the essential bits of assembly programming in x86_32 using gnu assembler. Seriously, read it, you'll gain a lot of knowledge.
I used this book when first learning assembly, and even though I am not a native english speaker, I got it all. It's a very easy and enjoyable read. No bullshit, just good explanations.

Speaking of books and bullshit - I fucking hate Tanenbaum books. I probably have said it already, but fuck this wealthy roody-poo. He just can't explain things succinclty. It's always a lot of words and unfunny jokes.
I'll look at it, hopefully it has a digital version on anna's, thanks for the recc
 
What the fuck. Genuinely what the fuck do you mean i gotta go around in spirals to parse C??
Yes.

But you are not going to use this technique often - it's useful only when you have some complex shit like array of function pointers, which is rare.

If you are interested in C++, I'd also recommend a book called 'Programming Principles and Practice using C++'. It might be old, but it explains the core language stuff pretty good. It is also written by the original designer of the language, which is good.
 
Last edited:
What the fuck. Genuinely what the fuck do you mean i gotta go around in spirals to parse C??
The whole "spiral" terminology is counterproductive. All you need to know is that unary postfix operators have higher precedence than unary prefix operators. This means that int *f(void); declares a function, f, that takes no arguments and returns a pointer to an int, because the argument list (void) has higher precedence than the indirection operator *. So f() evaluates to a pointer to an integer and *f() evaluates to the contents of the memory address that the return value points to. (The C declaration model is usually described as "declaration mimics use" for this reason.) It also means that int (*f)(void); declares a variable, f, that points to a function that takes no arguments and returns an int, because the parentheses override the default operator precedence.
 
What the fuck. Genuinely what the fuck do you mean i gotta go around in spirals to parse C??
It's just another one of those little fucky wuckies in the language that an extra five minutes of thought would've eliminated. There's even a traditional UNIX command that parses this stupid syntax and explains it in English.
I'll look at it, hopefully it has a digital version on anna's, thanks for the recc
Even better, it's available legally here.
 
Back
Top Bottom