This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Use enum instead of nested macros


"H.J. Lu" <hjl.tools@gmail.com> writes:
> On Thu, Oct 15, 2009 at 4:46 PM, David Daney <ddaney@caviumnetworks.com> wrote:
>> H.J. Lu wrote:
>>>
>>> I am checking in this patch to use enum instead of nested macros.
>>
>> [...]
>>>
>>> +enum
>>> +{
>>> + ?REG_80 = 0,
>>> + ?REG_81 = REG_80 + 1,
>>> + ?REG_82 = REG_81 + 1,
>>
>> Am I missing something, or is every single one of your ' = foo + 1' in this
>> patch completely redundant?
>
> Do all compiler guarantee that bar == 1 with
>
> enum
> {
>   foo = 0,
>   bar
> };
>
> If yes, I'd love to get rid of "foo + 1".

Yes.  6.7.2.2#3:

  The identifiers in an enumerator list are declared as constants that
  have type int and may appear wherever such are permitted.107) An
  enumerator with = defines its enumeration constant as the value of the
  constant expression. If the first enumerator has no =, the value of
  its enumeration constant is 0. Each subsequent enumerator with no =
  defines its enumeration constant as the value of the constant
  expression obtained by adding 1 to the value of the previous
  enumeration constant. (The use of enumerators with = may produce
  enumeration constants with values that duplicate other values in the
  same enumeration.) The enumerators of an enumeration are also known as
  its members.

Adam


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]