Enums, bitfields and wl_arrays

Erik De Rijcke derijcke.erik at gmail.com
Tue Oct 13 08:18:19 PDT 2015


On Tue, Oct 13, 2015 at 4:35 PM, Nils Chr. Brause <nilschrbrause at gmail.com>
wrote:

> Hi,
>
> On Mon, Oct 12, 2015 at 11:08 AM, Pekka Paalanen <ppaalanen at gmail.com>
> wrote:
> > On Mon, 12 Oct 2015 10:41:22 +0200
> > Erik De Rijcke <derijcke.erik at gmail.com> wrote:
> >
> >> Adding enum members is backward compatible for Java. If you compile
> against
> >> an enum with 2 members, and later on a new member is added, you can
> simply
> >> use the new version of the enum.
> >>
> >> Important however is that the order of old members do not change when
> new
> >> members are added.
> >
> > This is important. I don't think anyone has ever mentioned anything
> > like this before.
> >
> > We certainly have not expected the order to matter inside an <enum>
> > tag, since we require the value to be explicitly given. Not when you
> > are coming from C, anyway.
>
> In C++ the order doesn't matter either, since each entry has a defined
> value.
> I wonder why this is different in Java?
>
Because Java is not C/C++. In Java, enum values are unique by instance
alone. It does not have user 'defined' value(s) that make it unique. It
*can* have user defined properties (like any object) in addition to
 implicit compiler generated enum type specific properties. One of those
properties is it's "ordinal". Change the order of the enums and the ordinal
property will change, which can cause undefined behavior. Now you need to
wonder no more. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20151013/1a835f4d/attachment.html>


More information about the wayland-devel mailing list