logoalt Hacker News

jandreselast Tuesday at 5:18 PM2 repliesview on HN

    This:

    struct Vec3* v = malloc(sizeof(struct Vec3));

    is better written as:

    struct Vec3 * const v = malloc(sizeof *v);
I don't love this. Other people are going to think you're only allocating a pointer. It's potentially confusing.

Replies

f1shylast Tuesday at 5:51 PM

I also personally find totally confusing leaving the * in the middle of nowhere, like flapping in the breeze.

show 1 reply
unwindlast Tuesday at 9:08 PM

Uh, okay, but if you need to constantly write code as if people reading it don't understand the language, then ... I don't know how to do that. :)

It's not possible to know C code and think that

    sizeof *v
and

    sizeof v
somehow mean the same thing, at least not to me.
show 1 reply