Re: Consideration on pointer declarations



On Thu, 05 Mar 2009 12:10:18 +0000, Ben Bacarisse
<ben.usenet@xxxxxxxxx> wrote:

Starman <t.robelin@xxxxxxxxx> writes:

This is something I've pondered on for some years. The pointer symbol
* is tied to the variable, not to the type. So in all the code I've
seen so far I found:

char *pc;

I would say this the more common form (some people consider a third:
'char * pc;' by lets forget about that, yes?).


No, let's not. My preferred style is to line things up
vertically, one declaration per line, each line commented with a
description of the variable. (Quite often I'm not that fussy in
practice.) Here is an example (horizontal space trimmed for
posting).

DELIVERY {
AGENT_R agent_r; /* Agent receiving delivery */
PORT_NO port; /* Port receiving delivery */
size_t seqno; /* Expected inport serial number */
INPORT * inport; /* Pointer to agent inport struct */
};

This may seem anal rententive, but I have found that it is very
good practice, both for writing code and for reading it later.
Thus, your coding experience will be happier if every variable
has a clear, well defined meaning. Putting one declaration per
statement has the happy side effect of never missing one of those
asterisks.






Richard Harter, cri@xxxxxxxx
http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.
.



Relevant Pages

  • Re: Building from existing files - was Bypassing the Conversion Wi
    ... I have a problem in the future - as I did with the posting for the C4267 ... You have not justified why you are using the obsolete data type 'char' to represent text, ... the declaration) you should have been using a size_t variable. ... Unless there is a good reason to change the code, I see no advantage in it. ...
    (microsoft.public.vc.mfc)
  • Re: How to convert Infix notation to postfix notation
    ... literals to a function that takes char *. ... be good programming practice for you. ... No, it's not standard practice, it's stupid unwise unsafe bad ... Because they are spamming the discussion, ...
    (comp.lang.c)
  • Re: How to convert Infix notation to postfix notation
    ... literals to a function that takes char *. ... be good programming practice for you. ... No, it's not standard practice, it's stupid unwise unsafe bad ... Because they are spamming the discussion, ...
    (comp.lang.c)
  • Re: Consideration on pointer declarations
    ... cri@xxxxxxxx (Richard Harter) writes: ... 'char * pc;' by lets forget about that, ... good practice, both for writing code and for reading it later. ... Putting one declaration per ...
    (comp.lang.c)
  • Re: More performance tests of different AES implementations
    ... > I don't think that the restriction of having unsigned char ... > to be 8 bits in size is highly significant in practice. ... it should be noted that computing with a ...
    (sci.crypt)

Loading