Most of the time, I declare only one pointer/reference/etc per line, and it simply shows you instantly what type you are using. In the end, it's char* type. I like it that way. Do as you prefer. Compiler won't mind. |
This.
The
char* a, b, c;
issue is a weird inconsistency of C that's been inherited by C++. In most contexts in C/C++,
char*
is treated syntactically as a type in the same way as, say,
char
would. Writing
char* a
separates the type from the variable name in a natural way.
Yes, you have to remember the
char* a, b, c;
gotcha, but, like MatthewRock, I tend to declare one variable per line, so it's never an issue for me.
EDIT: If I really, really wanted to declare multiple variables in a line, and make one of them a pointer, I would make an exception to my usual style and write:
char *a, b, c;
just to make it clear that only
a is a pointer, and the rest are chars.
But I can't imagine any circumstances under which I would decide to declare multiple variables of different types on a single line like that.