Do you prefer "int* a;" or "int *a;"?
Personally, I think "int* a;" is the only right thing to do, since I am creating a pointer to an int, and not to ''a''.
By the way, C++ should be called ++C.
I also group * with the type, not the variable. It''s natural since it belongs to the type. But I''ve seen that some people can''t decide and do "int * a;"
AP pointed out the defect of putting * with the type. But I can live with that (a bug with that would be caught compile time anyway).
AP pointed out the defect of putting * with the type. But I can live with that (a bug with that would be caught compile time anyway).
As anonymous poster mentioned int* a; is not a good idea. Here''s why.
If you do something like int* a, b; you might mistake it for two pointers, while in reality b will be an integer, not a pointer. The right way to declare two pointers would be int* a, *b; This looks a little weird. This is why I prefer int *a;
If you do something like int* a, b; you might mistake it for two pointers, while in reality b will be an integer, not a pointer. The right way to declare two pointers would be int* a, *b; This looks a little weird. This is why I prefer int *a;
Yeah, I group * with the type (since it's really part of the type specification) and & with the variable (since it isn't, really). Of course, the multiple declaration thing does cause problems, but not subtle ones, and it's pretty easy to keep in mind.
int* a, b;
If I ever saw this in actual code, I would fire the programmer, or curse his bloodline, depending on how much actual power I had over him. The circumstances under which declarations should be put on the same line are very rare, and I can't think of a single situation in which declaring variables of different types on the same line would make a bit of sense.
How appropriate. You fight like a cow.
[edited by - sneftel on April 7, 2003 5:10:14 AM]
int* a, b;
If I ever saw this in actual code, I would fire the programmer, or curse his bloodline, depending on how much actual power I had over him. The circumstances under which declarations should be put on the same line are very rare, and I can't think of a single situation in which declaring variables of different types on the same line would make a bit of sense.
How appropriate. You fight like a cow.
[edited by - sneftel on April 7, 2003 5:10:14 AM]
quote:Original post by CoffeeMugOh the horror. But the compiler would catch it and you''d immediately spot the flaw.
If you do something like int* a, b; you might mistake it for two pointers, while in reality b will be an integer, not a pointer.
quote:Original post by Anonymous Poster
only problem is to declare more than 1 on a line it has to be int* a, *b, *c;
Then don''t declare more than 1 per line. Or do like this:
int* a; int* b; int* c;
Update GameDev.net system time campaign - success at last
I''ve settled into int* a lately, simply so that the asterisk looks less like operator *.
every average c programmer knows that this "problem" exists, and like civguy said, the compiler will catch it in many cases, so there is actually no problem.
LOL! i would rather fire him if he named his variables a,b,c instead of more meaningful names.
quote:Original post by Sneftel
int* a, b;
If I ever saw this in actual code, I would fire the programmer, or curse his bloodline, depending on how much actual power I had over him.
LOL! i would rather fire him if he named his variables a,b,c instead of more meaningful names.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement