0

in linux/fs.h I found strange struct file_operations:

struct file_operations fops = {
    read: device_read,
    write: device_write,
    open: device_open,
    release: device_release
};

and my questions is what is the name of this type of giving value?

Ôrel
  • 7,044
  • 3
  • 27
  • 46
Aetch
  • 11
  • 2
  • 3
    Please assume that I am using a screenreader and trying to answer your question. Can you see the problem? – Yunnosch Aug 21 '20 at 11:41
  • 2
    please don't use images, write code. By the way, where do you find it ? Because https://github.com/torvalds/linux/blob/master/include/linux/fs.h#L3397 – Ôrel Aug 21 '20 at 11:42
  • this is an initialization, the struct fields are pointer to function, the form is their initialization – bruno Aug 21 '20 at 11:45
  • and those _strange_ things are called function pointers. – Sourav Ghosh Aug 21 '20 at 11:45
  • 1
    Does this answer your question? [":" (colon) in C struct - what does it mean?](https://stackoverflow.com/questions/8564532/colon-in-c-struct-what-does-it-mean). One of its [answers](https://stackoverflow.com/a/19691081/3440745) describes **exactly** your example. – Tsyvarev Aug 21 '20 at 12:06

1 Answers1

1

From https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html

2.4.2.3 Initializing Structure Members

Another way to initialize the members is to specify the name of the member to initialize. This way, you can initialize the members in any order you like, and even leave some of them uninitialized. There are two methods that you can use. The first method is available in C99 and as a C89 extension in GCC:

struct point first_point = { .y = 10, .x = 5 };

You can also omit the period and use a colon instead of ‘=’, though this is a GNU C extension:

struct point first_point = { y: 10, x: 5 };

So this is equivalent to

struct file_operations fops = {
    .read = device_read,
    .write = device_write,
    .open = device_open,
    .release = device_release
};
Ôrel
  • 7,044
  • 3
  • 27
  • 46