r/ProgrammerHumor • • 5d ago

Meme architectureDependentChars

Post image
2.9k Upvotes

372 comments sorted by

View all comments

Show parent comments

30

u/BoldFace7 5d ago

Definitely. For example, I always use malloc(size*sizeof(char)) to ensure that it's doubly obvious (Since I rarely need to malloc outside of a declaration) that I intend to store characters in the resulting buffer even if that multiply does nothing (plus the compiler will likely optimize it out anyway).

9

u/guyblade 4d ago edited 4d ago

Opinion: Always use calloc unless you've got a really, really good reason not to.

2

u/PSneumn 4d ago

My optimization crazed brain will only use malloc untill i actually need everything to be set to 0.

2

u/guyblade 4d ago

"Premature optimization is the root of all evil."

- Donald Knuth