this post was submitted on 18 Oct 2024
256 points (99.2% liked)

Programming Horror

2162 readers
1 users here now

Welcome to Programming Horror!

This is a place to share strange or terrible code you come across.

For more general memes about programming there's also Programmer Humor.

Looking for mods. If youre interested in moderating the community feel free to dm @Ategon@programming.dev

Rules

Credits

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] zaphod@sopuli.xyz 13 points 10 months ago (3 children)

You don't need to cast the return value from malloc.

[–] addie@feddit.uk 10 points 10 months ago (1 children)

True. Although given how easy it is to cast void pointers to the wrong damn thing, it would be nice if you did, makes refactoring much easier. Makes me appreciate std::any all the more.

[–] embed_me@programming.dev 3 points 10 months ago* (last edited 10 months ago)

Void pointer should be avoided anyways. Even I find them rare and I mostly work in embedded RTOS

[–] Subverb@lemmy.world 6 points 10 months ago* (last edited 10 months ago)

This isn't malloc though. I have to assume the cast is because the user has experience with the output from an LLM being untrustworthy.

[–] vrighter@discuss.tchncs.de 2 points 10 months ago (1 children)
[–] zaphod@sopuli.xyz 2 points 10 months ago (1 children)
[–] vrighter@discuss.tchncs.de 1 points 10 months ago

that is besides the point. You can still call malloc, it will still return void*, and it would still reqoire casting in c++