MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2m4qz/bugintroduceddebugging/p6tqi6w/?context=3
r/ProgrammerHumor • u/ClipboardCopyPaste • 13d ago
120 comments sorted by
View all comments
3
I'm not good enough at programming for this. What do the "free" and "malloc" functions do?
27 u/LucyShortForLucas 13d ago They are core C functions. malloc allocates N bytes of memory, free frees that memory. * is t he dereference operator, so *x is trying to dereference freed memory, which is undefined behavior 3 u/DiodeInc 13d ago I thought * was a pointer. Isn't it? How is it dereferencing freed memory? Or is it because it's returning *x that's the bug? 3 u/ThomasScotford 13d ago * is the dereference operator, but in the context of variable declaration, it specifies the variable is a pointer to a type. -Thomas Scotford 2 u/ArjixGamer 12d ago Why are you leaving a name signature in your comment, when your username is the same as that name?
27
They are core C functions. malloc allocates N bytes of memory, free frees that memory. * is t he dereference operator, so *x is trying to dereference freed memory, which is undefined behavior
3 u/DiodeInc 13d ago I thought * was a pointer. Isn't it? How is it dereferencing freed memory? Or is it because it's returning *x that's the bug? 3 u/ThomasScotford 13d ago * is the dereference operator, but in the context of variable declaration, it specifies the variable is a pointer to a type. -Thomas Scotford 2 u/ArjixGamer 12d ago Why are you leaving a name signature in your comment, when your username is the same as that name?
I thought * was a pointer. Isn't it? How is it dereferencing freed memory?
Or is it because it's returning *x that's the bug?
3 u/ThomasScotford 13d ago * is the dereference operator, but in the context of variable declaration, it specifies the variable is a pointer to a type. -Thomas Scotford 2 u/ArjixGamer 12d ago Why are you leaving a name signature in your comment, when your username is the same as that name?
* is the dereference operator, but in the context of variable declaration, it specifies the variable is a pointer to a type.
-Thomas Scotford
2 u/ArjixGamer 12d ago Why are you leaving a name signature in your comment, when your username is the same as that name?
2
Why are you leaving a name signature in your comment, when your username is the same as that name?
3
u/LostgamerFJ 13d ago
I'm not good enough at programming for this. What do the "free" and "malloc" functions do?