What does a dot before the variable name in struct mean? What does a dot before the variable name in struct mean? linux linux

What does a dot before the variable name in struct mean?


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

In a structure initializer, specify the name of a field to initializewith ‘.fieldname =’ before the element value. For example, given thefollowing structure,

struct point { int x, y; }; 

the following initialization

struct point p = { .y = yvalue, .x = xvalue }; 

is equivalent to

struct point p = { xvalue, yvalue };


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.