Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pointer notation convention

Status
Not open for further replies.

javaguy1

Programmer
May 14, 2003
136
US
consider the function header

void myFunction(int *count)

i prefer

void myFunction(int* count)

the book i am using does it the first way. i like the second way because then my variable name looks like other variable names. * is a part of the type not the name. which way is most common?
 
probably the first since that is the way it is taught also if you declare multiple variables in a statement you have to do it anyway.

int *pint1, *pint2, *pint3;

The compiler doesn't care so do it how you want. I frequently use the other format myself

int* pint;

of course white space is irrelevant so

int * pint;


[cheers]

-pete
 
I use

int *pint;

Only because this has become the de facto convention. Neither one is inherently better.
 
I use int* pint because it emphasizes the fact that the pointer is part of the type.

I read somewhere (a reputable source, even) that this style was "used almost universally among C++ programmers." I somehow doubt that, but I still think a C++ programmer is more likely to stick the star on the type name than a C programmer is, since C++ emphasizes type more than value, and C is the other way around.

One problem with int* pint is the following:

int* a, b;

Logically, since the type is int*, a and b should both be int*s. Unfortunately, that's not the case. That's an argument to stick the star onto the variable name. I just avoid declaring more than one variable at a time and keep away from this problem altogether.
 
i do the same thing. one variable per line. it is good to know what happens though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top