From: Pedro Alves <palves@redhat.com>
To: John Baldwin <jhb@freebsd.org>, gdb-patches@sourceware.org
Cc: Yao Qi <qiyaoltc@gmail.com>
Subject: Re: [PATCH] gdb: Use vector::emplace_back
Date: Wed, 09 Nov 2016 15:27:00 -0000 [thread overview]
Message-ID: <79425cad-160f-d1a2-3275-29605db7a7cb@redhat.com> (raw)
In-Reply-To: <1575403.749fUSKQim@ralph.baldwin.cx>
On 11/09/2016 02:48 PM, John Baldwin wrote:
> On Wednesday, November 09, 2016 12:55:52 PM Pedro Alves wrote:
>> On 11/09/2016 12:42 PM, Yao Qi wrote:
>>
>>> I know leading underscore is used in some projects, so I want to know
>>> is it a C++ code standard that we use trailing underscore in this case or
>>> it is your personal coding habit. It is the latter.
>>
>> ...
>>
>>> Since the trailing underscore usage like this is not mentioned in C++
>>> code standard, people are free to use or not to use it. I don't have
>>> a preference on that.
>>
>> OK. I may ask a couple gcc people for their preference and see about
>> adding it to the docs. Each detail in the standard is based on
>> someone's personal preference that had sufficient following/agreement,
>> after all. :-)
>
> If the goal is to support -Wshadow then it would be nice to settle on a style
> so it is consistent across the tree.
It's not really about -Wshadow. In C++, in order to use a
member initializer, like in:
cmdarg (cmdarg_kind type_, char *string_)
: type (type_), string (string_)
{}
The parameter names really must be different from the
struct's elements.
This:
cmdarg (cmdarg_kind type, char *string)
: this->type (type), this->string (string)
{}
is not valid C++ and does _not_ compile:
src/gdb/main.c:450:7: error: expected identifier before ‘this’
: this->type (type_), this->string (string_)
^
This instead would work:
cmdarg (cmdarg_kind type, char *string)
{
this->type = type;
this->string = string;
}
However, using member initializer lists is a better
default, because there are cases where the above using
assignment wouldn't work or wouldn't be as efficient. E.g., in
case the element being constructed has a heavy constructor, does
not have a default constructor at all, or doesn't have an
assignment operator.
You can find more here:
http://stackoverflow.com/questions/926752/why-should-i-prefer-to-use-member-initialization-list
Thanks,
Pedro Alves
next prev parent reply other threads:[~2016-11-09 15:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-09 0:39 Pedro Alves
2016-11-09 11:12 ` Yao Qi
2016-11-09 12:21 ` Pedro Alves
2016-11-09 12:43 ` Yao Qi
2016-11-09 12:55 ` Pedro Alves
2016-11-09 14:50 ` John Baldwin
2016-11-09 15:27 ` Pedro Alves [this message]
2016-11-09 17:08 ` John Baldwin
2016-11-09 18:45 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=79425cad-160f-d1a2-3275-29605db7a7cb@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=jhb@freebsd.org \
--cc=qiyaoltc@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox