Please explain the use of ':' and trailing ',' in this C structure initialization code

static struct file_operations memory_fops = {
    open:       memory_open,    /* just a selector for the real open */
};

this is from mem.c file in uclinux

+3
source share
2 answers

This syntax is GNU-style initialization syntax; the member is openinitialized to memory_open, the rest remains uninitialized. C99 uses a different syntax ( .open = memory_open).

+6
source

In C, an optional trailing comma was allowed in initializers enclosed in brackets from the beginning of time. It exists so that you can use uniform comma placement in initializers, for example

struct SomeStructType s = {
  value1,
  value2,
  value3,
};

, , , . , .

:, , GCC, @geekosaur. C99 .

+3

All Articles