[Xcb] Are there any naming conventions for XCB?

Lucas Augusto Valentim Dantas lucasvalentim at outlook.com.br
Mon Mar 8 14:20:30 UTC 2021

I wasn't aware that the pointer value of the first member of a struct equals to the pointer value of the struct itself.

>From the C89 draft: "A pointer to a structure object, suitably
cast, points to its initial member (or if that member is a bit-field,
then to the unit in which it resides), and vice versa.  There may
therefore be unnamed holes within a structure object, but not at its
beginning, as necessary to achieve the appropriate alignment."

xcb_str_name() covers that necessity then.

De: Xcb <xcb-bounces at lists.freedesktop.org> em nome de Lucas Augusto Valentim Dantas <lucasvalentim at outlook.com.br>
Enviado: segunda-feira, 8 de março de 2021 08:11
Para: xcb at lists.freedesktop.org <xcb at lists.freedesktop.org>
Assunto: Re: [Xcb] Are there any naming conventions for XCB?

I am resending this e-mail to the list, I didn't notice I was replying to Uli directly, apologies.


The function is supposed to return the pointer to the current element in that iterator, I have found no function that does that in libxcb. Consider the program below:

#include <stdio.h>
#include <stdlib.h>

#include <xcb/xcb.h>

int main(void)
    xcb_connection_t *connection = xcb_connect(NULL, NULL);
    xcb_list_extensions_cookie_t cookie = xcb_list_extensions(connection);
    const xcb_list_extensions_reply_t *reply = xcb_list_extensions_reply(connection, cookie, 0);
    xcb_str_iterator_t str_iterator = xcb_list_extensions_names_iterator(reply);

    while(str_iterator.rem) { // verify if there are any elements left
        xcb_str_t *name = str_iterator.data; // gather the current element in the iterator
        int length = xcb_str_name_length(name);
        char *str = xcb_str_name(name);
        fwrite(str, sizeof(*str), length, stdout);

I don't know how useful this program is outside of an educational purpose, but notice that the members rem and data from the iterator has to be accessed by the user in order to finally convert it to a stringm then send that to stdout. If the members rem and data aren't supposed to be accessed by the user, I suggest creating a function to access them, or modify xcb_str_next to return a pointer to xcb_str_t for the current element, then have it iterate to the next element.
If the members of the struct xcb_str_iterator_t are supposed to be accessed by the user, then there is no reason to add said function.
De: Xcb <xcb-bounces at lists.freedesktop.org> em nome de Uli Schlachter <psychon at znc.in>
Enviado: domingo, 7 de março de 2021 05:35
Para: Lucas <lucasvalentim at outlook.com.br>; xcb at lists.freedesktop.org <xcb at lists.freedesktop.org>
Assunto: Re: [Xcb] Are there any naming conventions for XCB?


Am 14.02.21 um 23:37 schrieb Lucas:
> I want to introduce one function (another one might be needed) to return
> a xcb_str_t pointer from an iterator because I could not find a function
> to do just that, but I have noticed a pattern in the names of the
> function, hence the question. Here is the function:
> xcb_str_t *xcb_str_iterator_name(xcb_str_iterator_t *iterator)
> {
>     return iterator->data;
> }

Uhm, sorry, but *why*? Can't you just put this function into your own
code with a name of your liking? Why do you think this needs to be in

Also, are you sure the function above really does what you want it to
do? Aren't you instead looking for the already existing xcb_str_name()?

And for the question about naming conventions: Well... kind of. Since
most of the code is automatically generated from an XML description, I
guess "what the code generator does" is the naming convention. It all
maps pretty mechanical to the XML, I think.

This can be a, a little complicated. Listen, my advice is... ask
somebody else for advice, at least someone who's... got more experience
at...  giving advice.
Xcb mailing list
Xcb at lists.freedesktop.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/xcb/attachments/20210308/46700ed4/attachment.htm>

More information about the Xcb mailing list