结构类型本身可以作为c中的参数传递给函数吗?

结构类型本身可以作为c中的参数传递给函数吗?,c,wayland,C,Wayland,在研究wayland协议时,我发现函数以结构类型作为参数的代码 #include <wayland-server.h> static struct wl_compositor_interface compositor_interface = {&compositor_create_surface, &compositor_create_region}; int main() { wl_global_create (di

在研究wayland协议时,我发现函数以结构类型作为参数的代码

#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);
    }
wl_合成器_接口是结构类型,而不是变量名。但是wl_global_create()将结构类型作为函数参数。 有人能解释一下这是怎么回事吗


我读的源代码在这里

我浏览了源代码,其中既有一个
struct-wl\u-compositor\u接口
,也有一个变量
wl\u-compositor\u接口

包括底部的wayland服务器协议.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
,第二次引用的是变量。

您尝试过构建代码吗?它能建造吗?您是否检查过生成系统没有生成包含同名变量的代码(允许有同名的结构和变量)?是的,我编译了代码,gcc没有给出任何警告或错误。环境是ubuntu 17.04。我不记得gcc编译器的版本,但我认为它高于版本5。没有文件声明具有该名称的变量底线:否。但请注意,在您提供的代码片段中,
wl\u compositor\u interface
不是结构类型,而是结构标记。当你没有通过代码< >结构> /COD>关键字进行处理时,你所展示的东西在C中都是有意义的。你可能能够用宏来把一些东西用KBASH来表示,或者定义一个值代表了类型的枚举,但是这是C++中的,而不是C。
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);
};