octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: convention for declaring pointers?


From: John W. Eaton
Subject: Re: convention for declaring pointers?
Date: Mon, 24 Apr 2017 15:55:09 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

On 04/24/2017 01:40 AM, Mike Miller wrote:
On Sun, Apr 23, 2017 at 22:15:27 -0700, Rik wrote:
jwe,

Is there a convention for whether to cuddle the '*' for pointers with the
variable name, variable type, or neither?  I noticed in
liboctave/array/idx-vector.h declarations such as the following

idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep);

I started to change this to

idx_range_rep *r = ...

but then I realized that maybe the extra space is good.  It is consistent
with the rest of Octave coding conventions which tends to emphasize extra
whitespace for readability.  The space between the name of a function and
the opening parenthesis is an example of this openness.

I've always seen the style

    idx_range_rep *r = ...

preferred, and I think we pretty consistently prefer that in Octave so
far. It also helps emphasize that the '*' is required for each
declaration in a compound declaration like

    octave_idx_type *ridx, *cidx;

GNU indent also corrects the string "int * x" to "int *x".

Yeah, I've always used "int *x", probably from reading the first edition of K&R, which notes that "*x" is an int.

For references, however, I've always written "int& y", which is what I first saw in the first edition of TC++PL.

There is also this:  http://www.stroustrup.com/bs_faq2.html#whitespace

Currently, I think we mostly use "int *x" and "int& y" and would be happy to continue doing that. If you feel strongly that we should use consistent spacing for pointers and references, then I'd prefer

  "int* x" and "int& y"

over

  "int *x" and "int &y".

And I'd definitely prefer any of the above over using spaces on both sides of the "*" and "&".

jwe




reply via email to

[Prev in Thread] Current Thread [Next in Thread]