[Someone asked about whitespace in declarations, e.g. double *p versus double* p. Mark Brader sent this email reply to the original poster, but also copied me, and gave me permission to include the reply here.]
From: Mark Brader
Subject: Re: Newbie pointer question
There is no difference; it's a choice of style. White space next to a punctuation mark is significant in C in only four cases:
inside a string literal, as in " this "
inside a character constant, as in ' '
when it serves to keep two characters from making a combination that would have another meaning, as in
x = y / *p;where you don't want to form the /* comment sign; and
after the macro name in the definition of an object-like macro (one without an argument list) where the macro body starts with a ( character (and therefore looks like the argument list of a function-like macro), as in
#define X (z)which defines X to expand to (z), whereas if the space after X had been omitted it would define X with one argument and expanding to nothing.
With the above exception, you are free to use whitespace next to all punctuation marks, or not use it, whichever makes the program more understandable to the reader.
Some people choose to write
because they think it's clearer that this declares p as a double *. However,
double* p, q;
declares p as double * and q as double, not double *. So that style is very misleading in this case. The alternative
double *p, q;
is clearer for this declaration, and most people then use it on the first one
because consistency also contributes to clarity.
Not posted because I imagine someone else will say the same thing. Feel free to post this if you think it would make a useful contribution.
Mark Brader | "It's simply a matter of style, and while there firstname.lastname@example.org | are many wrong styles, there really isn't any SoftQuad Inc., Toronto | one right style." -- Ray Butterworth