c/c++语言开发共享结构类型本身可以作为c中的参数传递吗?

在研究wayland协议时,我发现函数将struct type作为参数。

#include  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); } 

wl_global_create的签名是

 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是结构类型,而不是变量名。 但是wl_global_create()将结构类型作为函数参数。 谁能解释一下这是如何工作的?

我读到的源代码就在这里。 https://github.com/eyelash/tutorials/blob/master/wayland-compositor/wayland-compositor.c

    我浏览了源代码,并且有一个struct wl_compositor_interface和一个变量wl_compositor_interface

    包含的wayland_server.h在底部包含了wayland-server-protocol.h 。 不幸的是,这不是在线提供的,而是在构建时生成的。 你可以得到它:

     $ git clone git://anongit.freedesktop.org/wayland/wayland $ cd wayland $ mkdir prefix $ ./autogen.sh --prefix=$(pwd)/prefix --disable-documentation $ make protocol/wayland-server-protocol.h 

    在这个文件中,它有(有些令人困惑)的定义:

     extern const struct wl_interface wl_compositor_interface; // On line 195 ... struct wl_compositor_interface { // Starting on line 986 void (*create_surface)(struct wl_client *client, struct wl_resource *resource, uint32_t id); void (*create_region)(struct wl_client *client, struct wl_resource *resource, uint32_t id); }; 

    它是第一次引用的struct ,第二次是变量。

      以上就是c/c++开发分享结构类型本身可以作为c中的参数传递吗?相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/522097.html

      (0)
      上一篇 2020年12月9日
      下一篇 2020年12月9日

      精彩推荐