i remember an online argument on a forum like 15 years ago where one set of people would say "each to their own" and the other would say "to each their own" and remarkably both sides were able to explain to the other why the syntax made sense to them. there were posts like "oh, you mean each person to their own preference!" i often think of it when there's some nomenclature thing which basically doesn't matter but both sides seem unable to see where the other is coming from

anyway, with this in mind, can someone explain something to me? in C, i tend to write this:

int* x;

i write it like that because i believe i am bringing into existence x, whose type is "a pointer to an integer". it's not an int, it's an int pointer. so i write int*, because that's what type it is. it seems clearer that way. however i often see this:

int *x;

this seems less clear, but some (most?) people obviously think THAT way is the clearer way. if you do, what's your thought process?

@jk I thought it was extremely confusing. The object type is a pointer to an integer, not an integer, so wouldn't it be attached to the type specifier?

Honestly hate "int *p"

@shram86 @jk it’s really unfortunate that C semantics are the way they are, because you’d think int* x, y; declares two variables of type int*, but instead * is treated like some pseudofact about x and y is just a plain int.

@senj @shram86 @jk Right, "int *x" is how the language _actually works_. It may not be how we wished it worked, but that is how it works, so it is clearer to write things that way.

If you designed C now, you might design it so that "int* x" is how it works. But that would be a slightly different language.

@WAHa_06x36 @senj @jk does this mean that when parsed, every C interpreter just transposes the asterisk?

Every compiler I've ever used doesn't care where it goes. I know K&R do it one way, but practice is different....

@shram86 @senj @jk I don't mean the literal position of the asterisk, I mean what it looks like it means. Does the asterisk belong to the type, or to the name of the variable. You can place it anywhere, but semantically, only one way matches the way the C language works, and that is "int *x", the asterisk belongs to the variable name, not to the type.

@WAHa_06x36 @senj @jk I'm still unsure of what you mean by "the asterisk belongs to the variable name".

By that logic you can have a int *x and an int x and C wouldn't care but I'm pretty sure it does?

@shram86 @senj @jk Well the classic example is still "int* x, y", which gives you one pointer to int and one int, not two pointers. There it's pretty easy to see that the * belongs to x, not to int.
@shram86 @senj @jk Also, for more complicated cases there is no equivalent of writing "int*". For instance, "int (*func)(int x)" gives you a pointer to a function taking an int and returning an int. You can't write "int(*)(int) func", which would be the equivalent of the "int* x".