Designated struct initializers with Visual C++

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
 
I

Irrwahn Grausewitz

(e-mail address removed) (Roland Dreier) wrote:

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.
Sorry, this is off-topic in comp.lang.c. Please take this question to a
VC++ specific newsgroup - that's where the experts for that kind of
problem hang out.

[OT]
AFAIK VC++ is far from getting close to C99 conformance, so I am not
surprised at all, personally.
[/OT]

Regards

Irrwahn
--
do not write: void main(...)
do not use gets()
do not cast the return value of malloc()
do not fflush( stdin )
read the c.l.c-faq: http://www.eskimo.com/~scs/C-faq/top.html
 
J

Jack Klein

On 13 Sep 2003 16:59:29 -0700, (e-mail address removed) (Roland Dreier)
wrote in comp.lang.c:

[snip]
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

<slightly_nasty>

I find it hard to believe that you expect a great deal of compliance
from Microsoft to any standard, including their own.

Don't get me started...

</slightly_nasty>
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
S

Serve La

Roland Dreier said:
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 doesn't work under VC. The two biggest commercial C compilers (Builder
and VC) do not intend to implement C99. Both companies say that this is
because nobody is asking for it, everybody seems to want C++ and that
standard *is* followed as much as possible. The only C99 feature I've seen
in VC7.1 is long long and it's format specifiers and that's probably because
it's in MS' own interest (64-bit windows?)

Please complain in microsoft.public.dotnet.languages.vc that's where I do my
complaining :)
There are some VC compiler guys hanging out there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top