Michel Feinstein
Michel Feinstein

Reputation: 14304

Using designated initializer with Structs in C

I wanted to test a very simple code but Visual Studio 2010 isn't compiling it. It's the first time I am using designated initializer with structs but it appears to be 100% correct since it's just a simple copy and paste from the wikipedia.

The code is:

#include <stdio.h>

/* Forward declare a type "point" to be a struct. */
typedef struct point point;
/* Declare the struct with integer members x, y */
struct point {
   int    x;
   int    y;
};

/* Define a variable p of type point, and set members using designated  initializers*/
point p = {.y = 2, .x = 1};

 int main()
{
    point p2 = {.y = 3, .x = 4}; //not even inside main it works
    return 0;
}

Visual Studio marks the dots in .y as red. Does anyone knows what's going on? I searched for other references in the internet and I can't see why my code is wrong. Is VS2010 not supporting a C feature?

Upvotes: 3

Views: 1533

Answers (1)

this
this

Reputation: 5301

Visual Studio 2010 c compiler supports only C89. Designated initializers are a C99 feature.

Upvotes: 11

Related Questions