I personally use same format rules as You. But I’m missing one important thing for young c/c++ programmers - information about declaration of multiple pointer variables. Because “int* a, b, c” results in A being pointer. B and C are normal int variables. Thus you should write “int *a, *b, *c” to create three pointers. Basically I don’t use this and prefer to create three separate declarations.
Thanks for pointing that out! That is indeed an argument for right-alignment, and I found it mentioned in technical documentation elsewhere.
You're also correct, however, that initializing three variables like that is typically bad form anyway. So, one could argue that if you avoid that practice as a rule, left-alignment still wins the day.
I'm a young c++ programmer and a veteran c# programmer and I have to say that the notation with the asterisk aligned to the left makes more sense to me. Alas, if writing “int* a, b, c” results in the declaration of the first variabile as a pointer to int and of the others two as int variables, from a logical point of view this closes the question for me: the right syntax requires to attach the asterisk to variable (it is no more a problem of alignment). Or the language is flawed (LOL). Bad form is one thing, another thing is wrong syntax.
Though, to follow my preferences and habits (and VC++ default formatting) I think I will use the asterisk aligned to the left and the pratice to write a separate declaration for any variabile.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I personally use same format rules as You. But I’m missing one important thing for young c/c++ programmers - information about declaration of multiple pointer variables. Because “int* a, b, c” results in A being pointer. B and C are normal int variables. Thus you should write “int *a, *b, *c” to create three pointers. Basically I don’t use this and prefer to create three separate declarations.
Thanks for pointing that out! That is indeed an argument for right-alignment, and I found it mentioned in technical documentation elsewhere.
You're also correct, however, that initializing three variables like that is typically bad form anyway. So, one could argue that if you avoid that practice as a rule, left-alignment still wins the day.
Edited the article to include all that. :)
I'm a young c++ programmer and a veteran c# programmer and I have to say that the notation with the asterisk aligned to the left makes more sense to me. Alas, if writing “int* a, b, c” results in the declaration of the first variabile as a pointer to int and of the others two as int variables, from a logical point of view this closes the question for me: the right syntax requires to attach the asterisk to variable (it is no more a problem of alignment). Or the language is flawed (LOL). Bad form is one thing, another thing is wrong syntax.
Though, to follow my preferences and habits (and VC++ default formatting) I think I will use the asterisk aligned to the left and the pratice to write a separate declaration for any variabile.