structs in C with initial values

Reference:

  1. Designated Initializers


//In a structure initializer, specify the name of a field to initialize with `.fieldname =' before the element value. For example, given the following structure,
struct point { int x, y; };

//the following initialization
struct point p = { .y = yvalue, .x = xvalue };

//is equivalent to
struct point p = { xvalue, yvalue };

//Another syntax which has the same meaning, obsolete since GCC 2.5, is `fieldname:', as shown here:
struct point p = { y: yvalue, x: xvalue };

results matching ""

    No results matching ""