What does a dot before the variable name in struct

2019-01-16 05:32发布

looking at the linux kernel source, I found this:

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 linux kernel
2条回答
虎瘦雄心在
2楼-- · 2019-01-16 06:02

It's sometimes called "designated initialization". This is a C99 addition, though it's been a GNU extension for a while.

In the list, each . names a member of the struct to initialize, the so called designator.

查看更多
smile是对你的礼貌
3楼-- · 2019-01-16 06:09

This is a Designated Initializer, which is syntax added for C99.

查看更多
登录 后发表回答