Connecting Tech Pros Worldwide Help | Site Map

Designated struct initializers with Visual C++

Roland Dreier
Guest
 
Posts: n/a
#1: Nov 13 '05
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
Irrwahn Grausewitz
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Designated struct initializers with Visual C++


roland@topspin.com (Roland Dreier) wrote:

<SNIP>[color=blue]
>
>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.
>[/color]
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
Jack Klein
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Designated struct initializers with Visual C++


On 13 Sep 2003 16:59:29 -0700, roland@topspin.com (Roland Dreier)
wrote in comp.lang.c:

[snip]
[color=blue]
> 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[/color]

<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
Serve La
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Designated struct initializers with Visual C++



"Roland Dreier" <roland@topspin.com> wrote in message
news:a6cb6392.0309131559.3358744e@posting.google.c om...[color=blue]
> 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
> };[/color]

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.


Closed Thread