Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Initialization of constants...

Reply
Thread Tools

Initialization of constants...

 
 
Werner
Guest
Posts: n/a
 
      10-30-2012
Hi all,

The following code snippet does not compile under GCC > 4.6:

namespace { //anonymous
const bool error_notImplemented;
}//end namespace anonymous

Removing the const causes it to compile. I'm surprised by
this behaviour. I would have thought that zero-initialization
would kick in here. I can't make up my mind about what the
standard says about this case. Any hints?

{PS. I realize const bool error_NotImplemented( false ) would be
sufficient and more verbose, but is it required by standard?}

Kind regards,

Werner

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-30-2012
On 10/30/2012 3:58 AM, Werner wrote:
> The following code snippet does not compile under GCC > 4.6:
>
> namespace { //anonymous
> const bool error_notImplemented;
> }//end namespace anonymous
>
> Removing the const causes it to compile. I'm surprised by
> this behaviour. I would have thought that zero-initialization
> would kick in here. I can't make up my mind about what the
> standard says about this case. Any hints?


Since it's a namespace object, it has static storage duration, and it's
supposed to be zero-initialized (i.e. to 'false') before the program
starts. Hence there should be no need to explicitly initialize it (see
[basic.start.init]/2). _HOWEVER_ there is another requirement (see
[dcl.type.cv]/1) which says that "If a cv-qualifier appears in a
decl-specifier-seq, the initdeclarator-list of the declaration shall not
be empty." It means that a declaration of an object with 'const' *must*
have an initializer.

> {PS. I realize const bool error_NotImplemented( false ) would be
> sufficient and more verbose, but is it required by standard?}


Yes AFAICS.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what's the difference between value-initialization and default-initialization? Jess C++ 23 05-04-2007 03:03 AM
array initialization in initialization list. toton C++ 5 09-28-2006 05:13 PM
Initialization of non-integral type in initialization list anongroupaccount@googlemail.com C++ 6 12-11-2005 09:51 PM
Initialization via ctor vs. initialization via assignment Matthias Kaeppler C++ 2 07-18-2005 04:25 PM
Default Initialization Vs. Value Initialization JKop C++ 10 09-22-2004 07:26 PM



Advertisments