[HarfBuzz] enum issue

Richard Wordingham richard.wordingham at ntlworld.com
Tue Mar 4 16:07:05 PST 2014


On Tue, 04 Mar 2014 14:45:12 -0800
Behdad Esfahbod <behdad at behdad.org> wrote:

> On 14-03-04 02:29 PM, Richard Wordingham wrote:
> > On Tue, 04 Mar 2014 10:47:47 -0800
> > Behdad Esfahbod <behdad at behdad.org> wrote:
> > 
> >> That negates the reason we added that line to begin with, which was
> >> to ensure all hb_tag_t's fit in hb_script_t.  How about:
> >>
> >>   _HB_SCRIPT_DUMMY1 = 0x7FFFFFFF,
> >>   _HB_SCRIPT_DUMMY2
> >>
> >> The idea being that DUMMY2 gets value of 0x80000000, ensuring that
> >> hb_script_t can represent up to 0xFFFFFFFF.
> > 
> > But the value of DUMMY2 is not a value of (32-bit) int!
> 
> Read again what Jonathan wrote:
> 
> """
> ISO C says:
> 
>   Each enumerated type shall be compatible with char, a signed
>   integer type, or an unsigned integer type. The choice of type is
>   implementation-defined, but shall be capable of representing the
>   values of all the members of the enumeration.
> 
> which is fine, but it also says:
> 
>   The expression that defines the value of an enumeration constant
>   shall be an integer constant expression that has a value
>   representable as an int.
> """

The next paragraph of C99 reads, removing (irrelevant) footnote
references:

"The identifiers in an enumerator list are declared as constants that
have type *int* and may appear wherever such are permitted. 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."

Are you claiming that DUMMY2 will have type *int* but will
nevertheless have value 0x80000000?  Note that this is a value that is
not representable as *int* if one use 2's complement 32 bit integers. 

Reading the text carefully, there is an expression that defines the
enumeration constant DUMMY2 and it is: 

(0x7FFFFFFF) + 1

This expression does not satisfy the constraint that its value be
representable as an *int*.

The only get out I can see is to argue that the 'value of an
enumeration constant' is not what the enumeration constant is defined
as.

Richard.



More information about the HarfBuzz mailing list