[Xcb] Xevent and XCBEvent

Jamey Sharp jamey at minilop.net
Mon May 23 18:01:32 PDT 2005


On Mon, 2005-05-23 at 15:52 -0700, Barton C Massey wrote:
> In message <1116874530.14854.21.camel at id.minilop.net> you wrote:
> > It turns out that gcc 3.3.5 (at least) will happily compile declarations
> > like this one, even with -Wall -pedantic -ansi, and even produce
> > reasonable results:
> > 
> > char buf[32 - sizeof(struct { int a; float b; char c; double d; })];
> 
> This is perfectly legal ANSI C, AFAIK.  Am I missing something?

Probably not. I only meant that it strikes me as an odd thing to do, and
yet it seems to work anyway.

> > So an extra pad field could be produced in that manner by re-emitting
> > the entire structure inside sizeof.
> 
> Why re-emit it rather than just reference it by type or tag?
> I'm not getting it...

I know I wasn't particularly clear in describing this suggestion; let me
re-state it. If there's an alternative option I've missed I think it
will be easier to see given the sequence of my reasoning.

We currently have some

        typedef struct {
                CARD8 kind;
                CADR8 bar;
                CARD16 sequence;
                CARD32 baz;
        } XCBFooEvent;

The above structure is 8 bytes, and we want to pad it to 32; given
knowledge of these numbers at code-generation time, we can do the
subtraction and insert

                char pad[24];

at the end. But we don't currently know those numbers at code-generation
time. (I think we should, if only so we can generate documentation. But
I don't think it's a priority right now.) So we could output a temporary
copy of the structure without padding, then output the real one using
the first to get the padding right:

        struct _XCBFooEvent {
                CARD8 kind;
                CADR8 bar;
                CARD16 sequence;
                CARD32 baz;
        };

        typedef struct {
                CARD8 kind;
                CADR8 bar;
                CARD16 sequence;
                CARD32 baz;
                char pad[32 - sizeof(struct _XCBFooEvent)];
        } XCBFooEvent;

But it's silly to pollute namespaces that way. So the best I can think
of is describing the structure type inline in the sizeof invocation.

Am I missing an option?

--Jamey



More information about the xcb mailing list