473,473 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Designated struct initializers with Visual C++

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
Nov 13 '05 #1
3 10386
ro****@topspin.com (Roland Dreier) wrote:

<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.

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
Nov 13 '05 #2
On 13 Sep 2003 16:59:29 -0700, ro****@topspin.com (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
Nov 13 '05 #3

"Roland Dreier" <ro****@topspin.com> wrote in message
news:a6**************************@posting.google.c om...
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.
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: vashwath | last post by:
Hi all, The following program is compiled using gcc with "-W" option. GCC is giving the following warning message initStructElem.c: In function `main': initStructElem.c:20: warning: missing...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
7
by: Russell Hind | last post by:
I want to create an array of key value pairs. This code compiles fine: KeyValuePair<string, object> kvps = { new KeyValuePair<string,object>( "int", 5 ), new KeyValuePair<string,object>(...
37
by: JohnGoogle | last post by:
Hi, Newbie question... After a recent article in VSJ I had a go at implementing a Fraction class to aid my understanding of operator overloading. After a previous message someone suggested...
18
by: Ehud Shapira | last post by:
Is it possible to have a declaration of a struct pointer initialized to an unnamed struct? (I'm only concerned with static/global variables, if it matters.) I'm trying to do something like: ...
6
by: Daniel Rudy | last post by:
Hello Group. Please consider the following code: /* this table is used in the wipedevice routine */ static const struct wipe_t { uchar wte; /* wipe table entry */ } wipetable = {...
1
by: r035198x | last post by:
Inspiration Inspired by a post by Jos in the Java forum, I have put together a little article on class initializers. Initializers are indeed underutilized by most Java programmers. Once the Java...
4
by: maria | last post by:
I have an array, string data, which produces the error "Too many initializers". Each one of the 248 rows has 5 items with a maximum total length of 173 characters. I am using Visual Studio...
10
by: Juha Nieminen | last post by:
I suppose you can never know C++ fully. I would have never guessed this actually compiles and works: struct Point { int x, y; }; struct Line { Point endpoint; int weight; };
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.