octave-maintainers
[Top][All Lists]
Advanced

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

Re: convention for declaring pointers?


From: Rik
Subject: Re: convention for declaring pointers?
Date: Mon, 24 Apr 2017 14:39:23 -0700

On 04/24/2017 12:55 PM, John W. Eaton wrote:
> 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 "&".

We can do whatever we like.  I made a note of our convention for pointers
and references at http://wiki.octave.org/C%2B%2B_style_guide.  And I fixed
up all the pointer instances in Octave to reflect the convention "int *x"
in this cset (http://hg.savannah.gnu.org/hgweb/octave/rev/e35a5c1233d0).  I
used grep, but apparently there were no occurrences of 'int & y'.

--Rik



reply via email to

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