Boost logo

Boost :

From: Glenn Schrader (gschrad_at_[hidden])
Date: 2007-01-09 12:39:11


I get the following error while compiling
libs/program_options/src/convert.cpp.

libs/program_options/src/convert.cpp:100: instantiated from here
libs/program_options/src/convert.cpp:48: warning: missing braces around
initializer for 'int [6]'

Line 48 is:

  std::mbstate_t state = {0};

The problem is simple but wasn't immediately obvious. The definition of
mbstate_t from the cwchar header is:

  typedef struct
  {
    int __fill[6];
  } mbstate_t;

The int[6] in the error message is actually coming from the first
element in mbstate_t. A change that makes the error go away is:

  std::mbstate_t state = {{0}};

Since I found cwchar in the include/c++/4.1.1 directory the layout of
this structure probably isn't guaranteed to be the same across compilers
or compiler versions. Perhaps the following would be better:

  std::mbstate_t state;
  memset( &state, 0, sizeof(state) );

Has anybody noticed whether this structure has the same definition
across compilers? (i.e. gcc, VC, SunCC, etc)

-glenn


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk