While studying wayland protocol, I found code that functions takes struct type as parameter.
#include <wayland-server.h>
static struct wl_compositor_interface compositor_interface =
{&compositor_create_surface, &compositor_create_region};
int main() {
wl_global_create (display, &wl_compositor_interface, 3, NULL,
&compositor_bind);
}
signature of wl_global_create is
struct wl_global* wl_global_create (struct wl_display *display,
const struct wl_interface *interface,
int version,
void *data,
wl_global_bind_func_t bind)
wl_compositor_interface is structure type, not a variable name. but wl_global_create() take structure type as function parameter. can someone explain how this works?
the source code I read is here. https://github.com/eyelash/tutorials/blob/master/wayland-compositor/wayland-compositor.c
I browsed through the source code, and there is both a
struct wl_compositor_interface
and a variablewl_compositor_interface
.The included
wayland_server.h
includes, at the bottom,wayland-server-protocol.h
. Unfortunately, this is not available online, but is generated at build time. You can get it with:In this file, it has the (somewhat confusing) definitions:
It's the
struct
that's being referenced the first time, and the variable the second.