[xkbcommon] Use an integer type for modifiers bit mask.
Bill Spitzak
spitzak at gmail.com
Fri Oct 4 10:43:50 PDT 2013
#include <iostream>
enum Enum {ZERO, A, B, C, D};
Enum operator|(Enum a, Enum b) { return Enum(int(a)|int(b)); }
int main() {
Enum a(A);
Enum b(B);
Enum c = a|b;
std::cout << a << ',' << b << ',' << c << std::endl;
}
Wander Lairson Costa wrote:
> 2013/10/4 Thiago Macieira <thiago.macieira at intel.com>:
>> On sexta-feira, 4 de outubro de 2013 09:09:32, Wander Lairson Costa wrote:
>>> The issued raised when I took code from window.c in the weston clients:
>>>
>>> mask = xkb_state_serialize_mods(input->xkb.state,
>>> XKB_STATE_DEPRESSED |
>>> XKB_STATE_LATCHED);
>>>
>>> g++ gave me a build error because I was passing an integer to enum
>>> parameter. C++ is a bit more nit-picky than C regarding implicit
>>> conversions. Therefore I had to use a cast.
>> Like you said, it's window.c. Why are you copy & pasting C code into a C++
>> file?
>>
>
> Well, weston clients are the only code reference I had in hand.
> Sometimes I go to qtwayland also, but it did not run away from the
> casts...
>
>>>> With the ABI that GCC uses, it's always at least 4 bytes.
>>> Personally, I don't like enum's in the ABI at all, because according
>>> to C/C++ standards, the compiler is free to choose whatever type it
>>> likes, and indeed I had problems with that in the past. C++11 fixed
>>> that [1]. But nevermind.
>> We're not relying on the ABI. I said "The enum must be backed by an integer
>> with at least as many bits as the enum possesses.". If you cast back from an
>> int that contains one of the enum values or an OR combination of enum values,
>> it *will* fit.
>
> I think I caused more confusion than explained here. My original point
> was not if the value fits or not, but that once you do whatever math
> with the enum, the result is not an enum type anymore (yes, sounds
> nit-picky)...
>
>
More information about the wayland-devel
mailing list