MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2m4qz/bugintroduceddebugging/p6ug62o/?context=9999
r/ProgrammerHumor • u/ClipboardCopyPaste • 2d ago
120 comments sorted by
View all comments
43
int* x = (int*) malloc(sizeof(int)); Since malloc returns void pointer you should parse it to type you use.
36 u/yjlom 2d ago void * coerces to any pointer type. This is valid: int *x = malloc(sizeof(int));. This is also valid (in C23): auto x = (int *) malloc(sizeof(int));. 36 u/Mateorabi 2d ago Get off my lawn with your newfangled auto keyword. 1 u/yjlom 2d ago The keyword ain't new, it's been used as a storage specifier since forever. What's new is overloading it for type inference. 4 u/Mateorabi 2d ago Hey when you learned C in the 90s it’s “new”. harumph. 1 u/yjlom 2d ago It's been there since the beginning, along with extern and static. You just don't tend to actually write it because it's the default inside functions and it doesn't make sense outside of them.
36
void * coerces to any pointer type. This is valid: int *x = malloc(sizeof(int));. This is also valid (in C23): auto x = (int *) malloc(sizeof(int));.
int *x = malloc(sizeof(int));
auto x = (int *) malloc(sizeof(int));
36 u/Mateorabi 2d ago Get off my lawn with your newfangled auto keyword. 1 u/yjlom 2d ago The keyword ain't new, it's been used as a storage specifier since forever. What's new is overloading it for type inference. 4 u/Mateorabi 2d ago Hey when you learned C in the 90s it’s “new”. harumph. 1 u/yjlom 2d ago It's been there since the beginning, along with extern and static. You just don't tend to actually write it because it's the default inside functions and it doesn't make sense outside of them.
Get off my lawn with your newfangled auto keyword.
1 u/yjlom 2d ago The keyword ain't new, it's been used as a storage specifier since forever. What's new is overloading it for type inference. 4 u/Mateorabi 2d ago Hey when you learned C in the 90s it’s “new”. harumph. 1 u/yjlom 2d ago It's been there since the beginning, along with extern and static. You just don't tend to actually write it because it's the default inside functions and it doesn't make sense outside of them.
1
The keyword ain't new, it's been used as a storage specifier since forever. What's new is overloading it for type inference.
4 u/Mateorabi 2d ago Hey when you learned C in the 90s it’s “new”. harumph. 1 u/yjlom 2d ago It's been there since the beginning, along with extern and static. You just don't tend to actually write it because it's the default inside functions and it doesn't make sense outside of them.
4
Hey when you learned C in the 90s it’s “new”. harumph.
1 u/yjlom 2d ago It's been there since the beginning, along with extern and static. You just don't tend to actually write it because it's the default inside functions and it doesn't make sense outside of them.
It's been there since the beginning, along with extern and static. You just don't tend to actually write it because it's the default inside functions and it doesn't make sense outside of them.
43
u/PR8-E 2d ago
int* x = (int*) malloc(sizeof(int)); Since malloc returns void pointer you should parse it to type you use.