Stylistic choice?

I've always thought that writing

1
2
int* iptr;
int& iref;


was more appropriate than writing

1
2
int *iptr;
int &iref;


Since it specifies the type. I know whitespace doesn't make a difference, and I'm not trying to start a war here, but I'm just curious what you guys think and what your preferences are.
*edit* typo
Last edited on
Because of the ability to declare multiple variables on the same line, specifically in functions, a lot of code bases dictate "int *iptr, *iptr2".

EDIT: Time for bed...
Last edited on
Interesting! It seems so obvious, but I hadn't considered it...
Though it should also be pointed out that a lot of code bases consider declaring multiple variable on the same line a bad practice and it is discouraged. Not all projects are like though from my personal experiences I haven't seen to much production level code which have multiple variables on declared on the same line. One interesting reason that a friend pointed out to me as to why they don't like this is because it can increase the chances for merge conflicts on unrelated changes.

In the end though it really comes down to your preference on the matter and what your projects style guidelines are.

a lot of code bases dictate "int *iptr, *iptr2".

Could you provide some examples of code bases which do this? Not saying you are wrong just curious about it because I mostly see projects restrict this in their code bases.

Anyways i personally prefer the first example, mainly because I see no real gain from having all the variables on a single line and to me it decreases the readability and is more error prone.
Last edited on
K&R and Linux kernel both come to mind when it comes to specifying where the star goes. I don't think most styles honestly care but from my experience, most people will tell you the same reasoning I gave anyways.
Ohh my mistake I thought you were talking about declaring multiple variables on the same line. Sorry about the that.
Last edited on
Topic archived. No new replies allowed.