structs and designated initializers

I have a struct like this:

struct Program {
	unsigned int duration;
	unsigned int speed;
	byte orientation;
	byte mode;
};

And then I want to do something like this:

struct Program currentProgram = { .duration = 3 };

The way I understand it, this should initialize duration to 3, but leave the other values at their default values (0). I know I can initialize a struct the normal way using the constructor, but then I need to specify all parameters. That's what I'm trying to avoid.

But I get this:

In function 'void loop()':
expected primary-expression before '.' token
braces around initializer for non-aggregate type 'Program'

I know that designated initializers are a C99 feature and for example not supported in Visual Studio C++. But some quick googleing suggests that AVR gcc should be able to do it. For example:
http://www.nongnu.org/avr-libc/user-manual/group__avr__fuse.html

Or am I just mangling the syntax here?

From the linked page:

If you are compiling in C++, you cannot use the designated initializers

ARG! Guess I should have read everything properly :frowning:

Then I'll probably just out everything. Not the end of the world, but it would have been nice :slight_smile:

You could provide your struct with a constructor that only takes the argument set you want to supply. However, if your reason for trying to eliminate the other initialisers is to simplify the code, this would probably be a step in the wrong direction - it might be worth while if you were going to use the constructor in a lot of places.