Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Struct syntax question

This question appeared when I recently opened a rather old driver for my raid device. To be able to compile the driver for a Linux system, I started to investigate on all those errors I got on output. And I came across this kind of syntax used in the driver sources:

struct file_operations t3_fops = {
        owner:                  THIS_MODULE,
        ioctl:                  ft_ioctl,
        fasync:                 ft_fasync,
        open:                   ft_open,
        release:                ft_release
};

So guys, could you help me to understand what does ":" mean? Is this C syntax at all? I know there is a bit field definition, but this looks rather different to me.

like image 373
Anton Avatar asked Jul 20 '11 07:07

Anton


People also ask

What is structure in C with syntax?

Structures (also called structs) are a way to group several related variables into one place. Each variable in the structure is known as a member of the structure. Unlike an array, a structure can contain many different data types (int, float, char, etc.).

Can you initialize variables in a struct C?

An important thing to remember, at the moment you initialize even one object/ variable in the struct, all of its other variables will be initialized to default value. If you don't initialize the values in your struct, all variables will contain "garbage values".

How do you declare a struct?

The general syntax for a struct declaration in C is: struct tag_name { type member1; type member2; /* declare as many members as desired, but the entire structure size must be known to the compiler. */ };

What is structure example?

Buildings, aircraft, skeletons, anthills, beaver dams, bridges and salt domes are all examples of load-bearing structures. The results of construction are divided into buildings and non-building structures, and make up the infrastructure of a human society.


1 Answers

This syntax for initializing structure members is called a designated initializer. The : is older GCC-specific syntax. This is documented in the GCC manual.

like image 135
sigjuice Avatar answered Sep 24 '22 08:09

sigjuice