谁能解释一下,这个结构初始化实际上是如何工作的?

标签 c struct coding-style initialization

struct audio_policy_service_ops {

audio_io_handle_t (*open_duplicate_output)(void *service,audio_io_handle_t output1,  
     int (*close_output)(void *service, audio_io_handle_t output);audio_io_handle_t output2);
     int (*suspend_output)(void *service, audio_io_handle_t output);
     int (*restore_output)(void *service, audio_io_handle_t output);
};

现在它们正在被初始化,如下所示:

struct audio_policy_service_ops aps_ops = {
    open_duplicate_output : aps_open_dup_output,
    close_output          : aps_close_output,
    suspend_output        : aps_suspend_output,
    restore_output        : aps_restore_output,
};

最佳答案

这是一个非标准的、特定于 GCC 的结构初始化语法。它通俗地称为“旧式 GNU struct init 语法”。它的标准等价物类似于

struct Foo bar = { .name1 = value1, .name2 = value2 };

您可以阅读更多相关信息 in the GCC documentation .

关于谁能解释一下,这个结构初始化实际上是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25452150/

相关文章:

c - 奇怪的运行时问题 : printf stops working midway

c++ - 将结构序列化为文件,并用字符串再次反序列化

c - 包含函数指针的结构,其自身作为 C 中的返回类型

python - `if something` 还是 `if something is not None` ?

iphone - 将 TTImageView 设置为 TTView 的背景

c++ - 返回 bool 值的函数的命名约定是什么?

c - 贪心算法返回的数量对于小值来说太大,但对于较大的值则不会

c - 如何将数组拆分为特定大小

c - 使用read和write做服务器和客户端(FTP协议(protocol))

c - 有没有办法转储 C 结构?