News for hackers. Stuff that matters.
Re:Everything I wish I knew when learning C by unsafecast on Monday November 28, 2022 @09:27AM (#33773967)
Because now you've got an int pointer and an int. The star associates with the right, not left.

I prefer to use the variant you described though, because it feels more natural to associate the pointer with the type itself. As far as I know, the only pitfall is in the multiple declaration thing so I just don't use it.

IMO, it's also more readable in this case:

    int *get_int(void);
    int* get_int(void);
The second one more clearly shows that it returns a pointer-to-int.
Re:Everything I wish I knew when learning C by thomastjeffery on Monday November 28, 2022 @01:30PM (#33777499)
Multiple declaration is generally frowned upon, because you declare the variables without immediately setting them to something.

If you always set new variables in the same statement you declare them, then you don't use multiple declarations, which means there is no ambiguity putting the * by the type name.

So convention wins out for convention's sake. And that's the entire point of convention in the first place: to sidestep the ugly warts of a decades-old language design.