I have made a struct which has several fields and I initialise like this:
MyStruct foo = {a, b, c, d, e};
I just added another field to the struct at the end, and I thought I would
have to add this new field to all of the initialisers but I dont, is this
defined behaviour?
Thanks
Allan
Here is my code:
/* define struct */
typedef struct
{
HWND xiParentWnd;
const char *xiCaption;
const char *xiTitle;
DWORD xiFlags;
DWORD xiNotifyMsg;
bool AutoDelete;
} AsyncMessageBoxInfo;
/* an example initialising the strcut */
AsyncMessageBoxInfo lAMBI = {NULL, "User is no longer logged in",
mRemoteUser, MB_OK | WS_EX_TOPMOST, NULL}; 2 1704
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message news:c9**********@news.freedom2surf.net... I have made a struct which has several fields and I initialise like this:
MyStruct foo = {a, b, c, d, e};
I just added another field to the struct at the end, and I thought I would have to add this new field to all of the initialisers but I dont, is this defined behaviour? Thanks Allan Here is my code:
/* define struct */ typedef struct { HWND xiParentWnd; const char *xiCaption; const char *xiTitle; DWORD xiFlags; DWORD xiNotifyMsg; bool AutoDelete; } AsyncMessageBoxInfo;
/* an example initialising the strcut */ AsyncMessageBoxInfo lAMBI = {NULL, "User is no longer logged in", mRemoteUser, MB_OK | WS_EX_TOPMOST, NULL};
Perfectly defined behaviour. AutoDelete would be set to zero.
I think `bool' is of an integral type.
Vijay
On Fri, 28 May 2004 12:32:36 +0100, "Allan Bruce" <al*****@TAKEAWAYf2s.com>
wrote: I have made a struct which has several fields and I initialise like this:
MyStruct foo = {a, b, c, d, e};
I just added another field to the struct at the end, and I thought I would have to add this new field to all of the initialisers but I dont, is this defined behaviour? Thanks Allan
Yes. 6.7.8/19 of the Standard says:
"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."
This applies to both arrays and structs; it seems to get discussed more
often in the context of array initialization, however (in fact, I
misinterpreted it just the other day...)
-leor
Here is my code:
/* define struct */ typedef struct { HWND xiParentWnd; const char *xiCaption; const char *xiTitle; DWORD xiFlags; DWORD xiNotifyMsg; bool AutoDelete; } AsyncMessageBoxInfo;
/* an example initialising the strcut */ AsyncMessageBoxInfo lAMBI = {NULL, "User is no longer logged in", mRemoteUser, MB_OK | WS_EX_TOPMOST, NULL};
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at: www.bdsoft.com/tools/stlfilt.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steven Bethard |
last post by:
In the "empty classes as c structs?" thread, we've been talking in some
detail about my proposed "generic objects" PEP. Based on a number of
suggestions, I'm thinking more and more that instead of...
|
by: Tim |
last post by:
Please advise if you can.
Presumably initialisation of members in member initialisation lists is
perfomed by 'C' run-time startup. If the CRT was never started-up would
those members be garbage?...
|
by: matro |
last post by:
hi there,
I have the following struct in my class:
class CTbStDialog : public CDialog
{
public:
int fooVar, fooVar2;
... //other foo variables...
|
by: sathyashrayan |
last post by:
The standard confirms that the following initialization of a struct
struct node
{
---
---
}
struct node var = {NULL};
|
by: Everton |
last post by:
The task at hand is to initialize a variable of
type "struct in6_addr" in a portable way. For instance:
/* NetBSD - /usr/include/netinet6/in6.h */
struct in6_addr {
union {
__uint8_t ...
|
by: seema |
last post by:
Hi all,
I am new to C++ programming. Can some body explain how to intialize the
structure values, consider this program,
#include <iostream.h>
struct mystruct
{
int a,b,c,d,e,f;
};
|
by: Frederick Gotham |
last post by:
I have just been reading 8.5 in the Standard, and am trying to make sense
of the different kinds of initialisations.
Up until now, I thought of an object as either NOT being initialised (i.e....
|
by: Yusuf |
last post by:
I'm sorry for the second post in as many hours, and both about structs.
The code below compiles. The variables test1 and test2 are structures
of datatype teststruct1 and teststruct2. The size of...
|
by: Grey Alien |
last post by:
If I have the ff struct:
struct A
{
unsigned int i;
char s;
} a, b;
And use them in code like this:
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |