结构体初始值设定项中的点 (.) 是什么意思?
static struct fuse_oprations hello_oper = {
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
我不太理解这个 C 语法。我什至无法搜索,因为我不知道语法的名称。那是什么?
static struct fuse_oprations hello_oper = {
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
I don't understand this C syntax well. I can't even search because I don't know the syntax's name. What's that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一项 C99 功能,允许您在初始值设定项中按名称设置结构的特定字段。在此之前,初始化程序只需按顺序包含所有字段的值——当然,这仍然有效。
因此,对于以下结构:
...您可以使用
...或:
...甚至:
...尽管最后两个仅适用于 C99。
This is a C99 feature that allows you to set specific fields of the struct by name in an initializer. Before this, the initializer needed to contain just the values, for all fields, in order -- which still works, of course.
So for the following struct:
...you can use
...or:
...or even:
...though the last two are for C99 only.
这些是 C99 的指定初始化器。
These are C99's designated initializers.
它被称为
指定初始化
(请参阅指定初始化器)。一个“初始化列表”,每个“.
”都是一个“
指示符
”在本例中命名了一个特定成员'
fuse_oprations
' 结构体,用于为指定的对象进行初始化'
hello_oper
' 标识符。Its known as
designated initialisation
(see Designated Initializers). An "initializer-list", Each '.
' is a"
designator
" which in this case names a particular member of the'
fuse_oprations
' struct to initialize for the object designated bythe '
hello_oper
' identifier.整个语法被称为指定初始化程序,正如 COD3BOY 已经提到的那样,当您需要在声明时将结构初始化为某些特定值或默认值时,通常会使用它。
The whole syntax is known as designated initializer as already mentioned by COD3BOY and it is used in general when you need to initialize your structure at the time of declaration to some specific or default values.