[xkbcommon] Use an integer type for modifiers bit mask.

Daniel Stone daniel at fooishbar.org
Fri Oct 4 06:28:21 PDT 2013


Hi,

On 4 October 2013 14:06, Wander Lairson Costa <wander.lairson at gmail.com> wrote:
> 2013/10/4 Daniel Stone <daniel at fooishbar.org>:
>> Well sure, but we took the added benefit of type safety (at least with
>> C compilers) over the the small potential downside.  I was fully aware
>> of the technical point there, but don't see it as much of a risk at
>> all.
>
> The problem can arise when you compile the lib with one compiler, and
> try to use it with another one. The was exactly the problem I had. I
> was responsible for an USB library that, on Windows, I used to build
> with Visual C++, but a client was using C++ Builder. Couple of hours
> with the disassembly and I discovered that Visual C++ chose a 32 bits
> types to represent the enum, but C++ Builder chose a 8 bits type...

Yeah, I'm aware of the risk ... luckily we target systems with more
coherent toolchains. ;) But still, we'll cross that bridge when we
come to it.

>> I really like the type safety aspect, so to be honest I'm just
>> inclined to make C++ wear the cast for now.
>
> If you change your mind, I can resubmit the patch with the integer type fixed :)

Well, we'd just be creating integer types and using them everywhere.
enum/integer conversions in C++ are not always cast-free either, and
all it means is that we'd be throwing away the type safety we have
today, and still not necessarily getting rid of the casts.

The reason I went for this is that the names can be confusing, and I'd
like to warn people very visibly and immediately when they get
something wrong.  Demoting everything to an integer removes that, so
I'd like to see the users who are hitting this just deal with the
cast.

Cheers,
Daniel


More information about the wayland-devel mailing list