[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
Message-ID: <9509101928.AA26628@sqrex.sq.com>
Bcc: scs@eskimo.com

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:

  1. inside a string literal, as in " this "

  2. inside a character constant, as in ' '

  3. 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
  4. 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

	double* p;

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

	double *p;

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
msb@sq.com              |   are many wrong styles, there really isn't any
SoftQuad Inc., Toronto  |   one right style."      -- Ray Butterworth