[Xcb] [PATCH] c_client.py: Prefer bit shifts over values in enum

Peter Harris pharris at opentext.com
Tue Jul 29 14:43:53 PDT 2014


On 2014-07-29 17:14, Ran Benita wrote:
> On Tue, Jul 29, 2014 at 04:59:12PM -0400, Peter Harris wrote:
>> On 2014-07-29 16:26, Daniel Martin wrote:
>>> Any idea or wish how I should change the patch, how the resulting value
>>> should like?
>>
>> 0x80000000 simply isn't representable in an enum in standard C.
> 
> Can you explain how this patch makes things worse in this regard?

It's signed overflow. (1 << 31) is an integer greater than INT_MAX.

Note also https://gcc.gnu.org/wiki/FAQ#signed_overflow

> (You mentioned a gcc extension, which one?).

https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html#Integers-implementation

Specifically, the two bullet points "The result of, or the signal raised
by, converting an integer to a signed integer type when the value cannot
be represented in an object of that type" and "The results of some
bitwise operations on signed integers".

In particular, "GCC does not use the latitude given in C99 and C11 only
to treat certain aspects of signed ‘<<’ as undefined, but this is
subject to change." Where 1<<31 appears to be one of the "certain
aspects", if I read the spec correctly.

Peter Harris
-- 
               Open Text Connectivity Solutions Group
Peter Harris                    http://connectivity.opentext.com/
Research and Development        Phone: +1 905 762 6001
pharris at opentext.com            Toll Free: 1 877 359 4866


More information about the Xcb mailing list