If you favor "T *var", do you ever write "T*"?

Posted by Roger Pate on Programmers See other posts from Programmers or by Roger Pate
Published on 2010-09-27T10:02:49Z Indexed on 2012/04/04 17:41 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

Thinking about where we place our asterisks; how do those that prefer to keep the "pointerness" away from the type and with the identifier (int *i) write code when the identifier is missing?

void f(int*); // 1
void f(int *); // 2

The former seems much more common, no matter what your preference when with the identifier. Is this a special case? What makes it an exception?

However, the first still isn't universal, because I have seen the latter style. Besides consistency along the lines of "there's always a space with the identifier, so we have one without", are there any other reasons to prefer it?

What about casts or array and function types? How would you re-write these:

(void*)var /*or*/ (void *)var

int[3] /*or*/ int [3]
// more relevant in C++ than C: Example<int[3]>

void(int) /*or*/ void (int)
// more relevant in C++ than C: std::function<void(int)>

The latter two would rarely, if ever, be used in C, but are seen with C++ templates.

© Programmers or respective owner

Related posts about coding-style

Related posts about c++