I have been using C for over thirty years, and I have never once called calloc().

· · Web · 4 · 2 · 9

@phooky some people like it because unlike malloc() it initializes all new memory to zero, and i guess the two parameters avoid potential overflows with malloc(num * sizeof(thing))


It's my go to over malloc() because initializing the contents to zero makes accidental dereferences much more predictable.

@suetanvil @phooky Huh. I must have heard about it, but I don't remember using it. It's been a while that I touched C. Sounds like a good idea though!

@phooky It's my standard use, except when I *know* the buffer will be overwritten immediately. And maybe even then, calloc is safer.

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!