[openbeos] Re: broken struct mouse_map in InterfaceDefs.h

  • From: "Andrew Bachmann" <shatty@xxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Mon, 12 Jan 2004 01:08:33 -0800 PST

Oops,

Looks like I lose in at least 2 ways:

Way #1: no R5 compiler supports anonymous structs as union members.
Way #2: anonymous unions in structs are C++ feature and will not
compile in C

So, for future reference all: no anonymous unions in structs in any
headers that are supposed to be C friendly.

In my searchings on this issue I also found a warning about interchanging
access to union members. (that is to say, using a union as a reinterpretation
of the members.)  Apparently the spec doesn't require such things to work
in the way you expect.  Even on a C++ compiler that supported what I
wrote earlier, for example, middle could be mapped to button[0] instead
of button[2] as one might expect.

I think we have to use separate structs.  Any other suggestions?

Andrew

"Andrew Bachmann" <shatty@xxxxxxxxxxxxx> wrote:
[snip]
> I think this is at least a source compatible version:
> 
> struct mouse_map {
>       union {
>               struct {
>                       uint32 left;
>                       uint32 right;
>                       uint32 middle;
>               };
>               uint32  button[B_MAX_MOUSE_BUTTONS];
>       };
> };
> 
> This still has a binary compat problem.  A better alternative
> would seem to be to use a new struct.
> 
> Andrew


Other related posts: