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

Ran Benita ran234 at gmail.com
Fri Oct 4 08:38:38 PDT 2013

On Fri, Oct 04, 2013 at 03:22:59PM +0200, David Herrmann wrote:
> Hi
> On Fri, Oct 4, 2013 at 2:34 PM, Daniel Stone <daniel at fooishbar.org> wrote:
> > On 4 October 2013 13:09, Wander Lairson Costa <wander.lairson at gmail.com> wrote:
> >> That's what the patch is about: avoid casts. Whenever you use a cast,
> >> you are giving up the help the compiler may give to you regarding
> >> invalid type conversions. So, I always use the rule of thumb of
> >> avoiding casts whenever I can. IMO, this is not a harmful patch and
> >> will make the C++ programmers a little bit easier.
> >
> > I can see where it's going, but on the other hand xkb_mod_mask_t is
> > _so_ not the right type.  That's a bitmask of actual modifiers (i.e.
> > the return value), not a bitmask of components.  So it avoids the
> > cast, but also makes the API look extremely misleading, as we've
> > documented exactly what xkb_mod_mask_t is.
> >
> > I really like the type safety aspect, so to be honest I'm just
> > inclined to make C++ wear the cast for now.
> We had a similar discussion when I pointed out that "enum" may change
> the underlying type without notice when adding new enum-values.

Just adding a note that this problem can be mitigated by adding some
dummy value to the enum to force it to be int-sized. Of course we can't
do it in xkbcommon, but future APIs may want to do this, at least if
they don't find it too ugly.


More information about the wayland-devel mailing list