It depends. For example, is a C-string a "char pointer" or a "pointer to char". If it's a "char pointer" then the asterisk goes next to the type because a pointer is a type in it's own right; if it's a "pointer to char" the asterisk goes next to the variable name because the pointer is an attribute of the variable.
Technically, it's the latter. If
char*
was it's own type, then you couldn't do this:
1 2
|
char* str, /* This is a pointer to char */
chr; ./* This is just a char */
|
Also, putting it next to the variable name is more consistent:
1 2 3
|
char* str = malloc(4096);
/* ... */
*str = 0;
|
The inconsistency is in the pointer dereference. The asterisk is next to the variable name there, but not when declaring the variable.
Having said that, I'll always put the asterisk(s) by the datatype. I think it looks neater.
@helios,
I thought that too.
---
inb4 holy war, <flamesuit>, etc.