C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

POD initialization, standard or extension?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Matthew D Moss
Guest





PostPosted: Fri Aug 18, 2006 4:54 am    Post subject: POD initialization, standard or extension? Reply with quote



Looking among some sample code, I found the following (names changed to
protect the innocent):


struct InitOptions
{
GLuint flags;
GLuint maxItems;
GLboolean initializeItems;
GLuint memorySize;
};

InitOptions opts =
{
flags: FLAG_A | FLAG_B,
maxItems: 1,
initializeItems: false,
memorySize: 128 * 1024 * 1024,
};

I've never seen structure initialization like that... Is this standard,
or a compiler extension?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Jiang
Guest





PostPosted: Fri Aug 18, 2006 6:35 am    Post subject: Re: POD initialization, standard or extension? Reply with quote



Matthew D Moss wrote:
Quote:
Looking among some sample code, I found the following (names changed to
protect the innocent):


struct InitOptions
{
GLuint flags;
GLuint maxItems;
GLboolean initializeItems;
GLuint memorySize;
};

InitOptions opts =
{
flags: FLAG_A | FLAG_B,
maxItems: 1,
initializeItems: false,
memorySize: 128 * 1024 * 1024,
};

I've never seen structure initialization like that... Is this standard,
or a compiler extension?


Designated Initializer is gcc extension.


http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Designated-Inits.html#Designated
-Inits


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ulrich Eckhardt
Guest





PostPosted: Fri Aug 18, 2006 6:01 pm    Post subject: Re: POD initialization, standard or extension? Reply with quote



Matthew D Moss wrote:
Quote:
struct InitOptions
{
GLuint flags;
GLuint maxItems;
GLboolean initializeItems;
GLuint memorySize;
};

InitOptions opts =
{
flags: FLAG_A | FLAG_B,
maxItems: 1,
initializeItems: false,
memorySize: 128 * 1024 * 1024,
};

I've never seen structure initialization like that... Is this standard,
or a compiler extension?

This in particular is a GCC extension. "like that" is standard, although
not C++ standard - it is part of C99 and is done slightly different (and
GCC supports that now, too):

InitOptions opts =
{
.flags = FLAG_A|FLAG_B,
.maxItems = 1,
.initializeItems = false,
.memorySize = 128 * 1024 * 1024,
};

On a side notice, C99 also added support for similar things with arrays:

int arr[20] = { [5]=1, [8]=6, [13]=7 };

Uli


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.