[Xcb] question regarding <typedef>

Josh Triplett josh at joshtriplett.org
Sun May 30 08:59:37 PDT 2010

On Sun, May 30, 2010 at 01:15:49PM +0200, Christoph Reimann wrote:
> Hi once more,
> while looking through the generated C code, I stumbled upon the
> translation of the typedef XML element.
> Example:
>   <typedef oldname="CARD32" newname="VISUALID" />
> This gets translated to the following declarations in the header file:
> typedef uint32_t xcb_visualid_t;
> typedef struct xcb_visualid_iterator_t {
>     xcb_visualid_t *data; /**<  */
>     int             rem; /**<  */
>     int             index; /**<  */
> } xcb_visualid_iterator_t;
> void
> xcb_visualid_next (xcb_visualid_iterator_t *i  /**< */);
> xcb_generic_iterator_t
> xcb_visualid_end (xcb_visualid_iterator_t i  /**< */);
> Why is the iterator code generated for a simple type? I grep'ed
> through libxcb and util code, and it seems it doesn't even get called
> somewhere. As far I understood it, iterator would make sense only for
> list types??

The iterator code exists primarily for handling structures of variable
length, which contain data after the portion defined in a C struct; the
iterators must skip that extra data too.  However, at some point we
decided that it seemed both easier and more consistent to use the
iterators for *all* types defined by XCB, even those which have a fixed
size.  It does look a bit silly in cases like this, though. :)

- Josh Triplett

More information about the Xcb mailing list