0

I am wondering about the following initialization scenario:

typedef struct {
  char[2] array;
} MyStruct;


Class MyClass {
public:
  Class() : _struct() {}

protected:
  MyStruct _struct;
};

After looking at the rules of value and aggregate initialization in C++11, it seems to me that

MyClass class;

will lead to class._struct.array being initialized with zeros in C++11. However, I was unable to find documentation about VS2013 in particular, showing that this is really guaranteed. Can anybody give a definite answer here?

Da Jogh
  • 61
  • 4
  • 3
    Why would Visual Studio need particular documentation about that? What you're talking about is behavior guaranteed by C++03; that's something VS should have supported long ago. It's like expecting to find documentation about virtual functions or templates. – Nicol Bolas Mar 08 '16 at 21:52
  • Well, MSDN contains documentation about virtual functions and templates, so this is really not an answer. Could you maybe explain according to which rule this is guaranteed since C++03? Looking at http://en.cppreference.com/w/cpp/language/value_initialization, for example, this is not evident to me. – Da Jogh Mar 08 '16 at 22:00
  • 1
    It is all there in the reference you linked. – juanchopanza Mar 08 '16 at 22:11
  • @user3766240 If a C++ compiler didn't initialize the array to zeros, the compiler is *severely* broken. – PaulMcKenzie Mar 08 '16 at 22:14
  • @ juanchopanza: Quoting myself: "this is not evident to me". An anwer like this is hence just pure non-sense. Just to increase the counter, as usual. @PaulMcKenzie: Well, VS was severly broken in this respect at least until 2010 afaik. This is exactly why I am asking. – Da Jogh Mar 09 '16 at 05:37

0 Answers0