473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

multiple named initialization of same member

Is the following legal, and if so is the behavior specified?

struct s {
int a;
const char *b;
};

int main(void) {
struct s test = {
.a = 12,
.b = "",
.a = 16,
};

return 0;
}

Nov 14 '05 #1
2 1419
William Ahern wrote:
Is the following legal, and if so is the behavior specified?

struct s {
int a;
const char *b;
};

int main(void) {
struct s test = {
.a = 12,
.b = "",
.a = 16,
};

return 0;
}

6.7.8 #19 IMO covers this:
,-
| The initialization shall occur in initializer list order, each
| initializer provided for a particular subobject overriding any
| previously listed initializer for the same subobject; all
| subobjects that are not initialized explicitly shall be initialized
| implicitly the same as objects that have static storage duration.
`-

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #2


William Ahern wrote:
Is the following legal, and if so is the behavior specified?

struct s {
int a;
const char *b;
};

int main(void) {
struct s test = {
.a = 12,
.b = "",
.a = 16,
};

return 0;
}


Yes (assuming C99) and yes. 6.7.8/19:

"The initialization shall occur in initializer list
order, each initializer provided for a particular
subobject overriding any previously listed initializer
for the same subobject [...]"

So your initialization produces test.a == 16, test.b pointing
to an empty string.

--
Er*********@sun.com

Nov 14 '05 #3

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

Similar topics

5
by: alex | last post by:
Hi, it is possible to define multiple initialization methods so that the method is used that fits? I am thinking of something like this: def __init__(self, par1, par2): self.init(par1,...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
5
by: Ricky Lung | last post by:
struct Foo { union { int& i; float& j; }; Foo(int& val) : i((int&)val), j((float&)val) {} };
6
by: Neil Zanella | last post by:
Hello, I would like to know whether the following C fragment is legal in standard C and behaves as intended under conforming implementations... union foo { char c; double d; };
10
by: utab | last post by:
Dear all, Can somebody direct me to some resources on the subject or explain the details in brief? I checked the FAQ but could not find or maybe missed. Regards,
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
3
by: Jess | last post by:
Hello, I've been reading Effective C++ about multiple inheritance, but I still have a few questions. Can someone give me some help please? First, it is said that if virtual inheritance is...
6
by: Christof Warlich | last post by:
Hi, the few lines of code below show different results depending on the compiler version (gcc-2.95 versus gcc-3.3 and later): gcc-2.95 first initializes d (line 9) and then t (line 8), as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.