This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: style convention: /*foo_p=*/ to annotate bool arguments
- From: David Brown <david at westcontrol dot com>
- To: Nathan Sidwell <nathan at acm dot org>, Martin Sebor <msebor at gmail dot com>, GCC Mailing List <gcc at gcc dot gnu dot org>, Jeff Law <law at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Cc: Aldy Hernandez <aldyh at redhat dot com>
- Date: Tue, 4 Oct 2016 14:04:08 +0200
- Subject: Re: style convention: /*foo_p=*/ to annotate bool arguments
- Authentication-results: sourceware.org; auth=none
- References: <672232b9-8cb4-71ad-ece6-e593545a4f07@gmail.com> <082feb91-80b1-7d1d-6bdd-d881268475ae@acm.org>
On 04/10/16 13:40, Nathan Sidwell wrote:
> On 10/03/16 19:48, Martin Sebor wrote:
>> In a recent review Jason and I discussed the style convention
>> commonly followed in the C++ front end to annotate arguments
>> in calls to functions taking bool parameters with a comment
>> along the lines of
>>
>> foo (1, 2, /*bar_p=*/true);
>
> I like this if there's more than one boolean arg. If there's only one,
> I'm ambivalent.
>
>
>> // In some header:
>> void foo (int, int, bool = -1);
>>
>> // In some .c file:
>> void foo (int x, int y, bool bar_p /* = false */)
>
> I think this is a good idea -- I've sometimes been puzzled by only
> looking at the defn, because it happened to be in the same file as the
> call site I was examining.
>
> As has been mentioned, this does allow the decl and in-def comment to
> diverge. How about something like:
>
> void foo (int, T = ...);
>
> void foo (int x, T y /* = default */)
> {
> }
>
> ?
>
> nathan
>
>
This would have been easier if C++ had allowed the same default value to
be given in both the declaration and the definition:
void foo(int x, int y, bool bar_p = false);
void foo(int x, int y, bool bar_p = false)
{
}
It seems strange that this is not allowed. The standard says "A default
argument shall not be redefined by a later declaration (not even to the
same value)", but I can't think /why/ it is not allowed.