From: Pedro Alves <palves@redhat.com>
To: Patrick Palka <patrick@parcs.ath.cx>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Type-safe wrapper for enum flags
Date: Tue, 03 Nov 2015 11:18:00 -0000 [thread overview]
Message-ID: <563897E6.30006@redhat.com> (raw)
In-Reply-To: <CA+C-WL8XvvJR_QnKkVX-Znkkk7zLr9COfQipsK8AMAhkuvedQQ@mail.gmail.com>
On 11/01/2015 03:19 PM, Patrick Palka wrote:
>> +
>> +public:
>> + /* Allow default construction, just like raw enums. */
>> + enum_flags ()
>> + {}
>
> Why not zero-initialize enum_value here? Given that enum_flags
> represents a bitwise OR of enum_type, it seems reasonable that its
> default value would be zero rather than uninitialzied.
My reasoning was to make this look as much as a raw enum as possible.
If one is zero initialized and other isn't, then I'm going to be
staring at (client) code wondering whether to initialize or not.
Making it be like raw enums, the rule is simple.
But, in any case, client code will still need to explicitly initialize
in C mode, as then the flags enum is just a typedef. Thus seems best
not to rely on default initialization as long as we support C mode.
> What are global operator^ and operator& omitted?
Simply because nothing in the code base trips on the
need for them. They'd be needed for things like:
flags f1 = ((enum flag_values) some_input_int) & FLAG_VAL1;
flags f2 = ((enum flag_values) some_input_int) ^ FLAG_VAL2;
I'll add them.
Thanks for the review!
--
Pedro Alves
next prev parent reply other threads:[~2015-11-03 11:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-30 8:12 Pedro Alves
2015-10-30 9:48 ` Pedro Alves
2015-10-30 17:08 ` Simon Marchi
2015-10-30 17:39 ` Pedro Alves
2015-10-31 20:11 ` Simon Marchi
2015-10-31 20:28 ` Pedro Alves
2015-11-01 2:07 ` Doug Evans
2015-11-03 11:48 ` Pedro Alves
2015-11-01 4:04 ` Doug Evans
2015-11-03 12:23 ` Pedro Alves
2015-11-01 15:19 ` Patrick Palka
2015-11-03 11:18 ` Pedro Alves [this message]
2015-11-09 13:25 ` Patrick Palka
2015-11-17 13:49 ` 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=563897E6.30006@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=patrick@parcs.ath.cx \
/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