Peretz Peretz - 5 months ago 31
C Question

Static struct initialization in C

I have a struct type as shown below:

typedef struct position{
float X;
float Y;
float Z;
float A;
} position;

typedef struct move{
position initial_position;
double feedrate;
long speed;
int g_code;
} move;

I am trying to statically initialize it, but I have not found a way to do it. Is this possible?

Answer Source

It should work like this:

move x = { { 1, 2, 3, 4}, 5.8, 1000, 21 };

The brace initializers for structs and arrays can be nested.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download