Linux struct 中变量名前的点是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7487918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does a dot before the variable name in struct mean?
提问by c0de
looking at the linux kernel source, I found this:
查看linux内核源代码,我发现了这个:
static struct tty_operations serial_ops = {
.open = tiny_open,
.close = tiny_close,
.write = tiny_write,
.write_room = tiny_write_room,
.set_termios = tiny_set_termios,
};
I've never seen such a notation in C. Why is there a dot before the variable name?
我从未在 C 中看到过这样的符号。为什么变量名前有一个点?
采纳答案by Reed Copsey
This is a Designated Initializer, which is syntax added for C99.
这是一个Designated Initializer,它是为 C99 添加的语法。
回答by sidyll
It's sometimes called "designated initialization". This is a C99 addition, though it's been a GNU extension for a while.
它有时被称为“指定的初始化”。这是 C99 的补充,虽然它已经成为 GNU 扩展有一段时间了。
In the list, each .
names a member of the struct to initialize, the so called designator.
在列表中,每个.
命名结构的一个成员进行初始化,即所谓的指示符。