R
Roland Dreier
I'm used to initializing struct fields by name using the designator
syntax that is a part of ISO C99. For example:
struct foo {
int x;
int y;
int z;
};
struct foo a = {
.x = 1,
.z = 3
};
This works perfectly under all the versions of gcc that I use.
Unfortunately, I've recently had to port some of my code to compile
with Microsoft Visual C++ under Windows. The code above gives a
syntax error, and I can't find anything in the Microsoft documentation
about any struct initializers other than the very basic:
struct foo a = { 1, 0, 3 };
This syntax is much more fragile, since changing the order of the
struct fields or adding a field will probably cause this to do the
wrong thing.
So, is there any way to initialize struct fields by name in Visual
C++? Am I missing a command-line option? I find it hard to believe
that Visual C++ still doesn't implement something that has been
standard C for 4 years.
Thanks,
Roland
syntax that is a part of ISO C99. For example:
struct foo {
int x;
int y;
int z;
};
struct foo a = {
.x = 1,
.z = 3
};
This works perfectly under all the versions of gcc that I use.
Unfortunately, I've recently had to port some of my code to compile
with Microsoft Visual C++ under Windows. The code above gives a
syntax error, and I can't find anything in the Microsoft documentation
about any struct initializers other than the very basic:
struct foo a = { 1, 0, 3 };
This syntax is much more fragile, since changing the order of the
struct fields or adding a field will probably cause this to do the
wrong thing.
So, is there any way to initialize struct fields by name in Visual
C++? Am I missing a command-line option? I find it hard to believe
that Visual C++ still doesn't implement something that has been
standard C for 4 years.
Thanks,
Roland