Re: Why keysym constants in gdk/gdkkeysyms.h are defined as macros, not as an enum?



2012/6/26, Christophe Fergeau <cfergeau gmail com>:
> Hey,
>
> 2012/6/26 Mark Vender <markv743 yahoo co uk>:
>> On 06/26/2012 05:31 PM, Bastien Nocera wrote:
>>>
>>> If we used enums, we would restrict the keysyms to the declared values.
>>
>>
>> Well, C doesn't actually have such restriction.
>
> Yes and no, if you assign an integer to a variable of an enum type,
> and if this integer is not one of the value defined for this enum
> type, then this is undefined behaviour in the C standard.
>

As far as you don't convert an int to an enum, there's no problem. You
just have to use a gint for keysym parameters.
e.g.

enum _InternalGdkKey {
GDK_KEY_BackSpace = 0xff08,
GDK_KEY_Tab = 0xff09
};

void gdk_do_something_on_a_key (gint key);

> Again, the C standard has some gotcha there, a compiler is allowed to
> use a char-sized integer or an int-sized integer to store an enum, so
> sizeof of an enum type can change if you add more values to it, which
> could be an ABI break. And this is not purely theoretical, I think
> llvm does this.
>

This is only a problem if you use the enum data type.

-- 
André Gillibert


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]