Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3301100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:43:13+00:00 2026-05-17T20:43:13+00:00

An hour ago I posted an answer here which according to me was correct.

  • 0

An hour ago I posted an answer here which according to me was correct. However my answer was downvoted by Martin B. He said

You’re just lucky and are getting zeros because the memory that i was placed in happened to be zero-initialized. This is not guaranteed by the standard.

However after reading Michael Burr’s answer here and trying the following sample code

1)

#include <cassert>

struct B { ~B(); int m; };

int main()
{
   B * b = new B();
   assert(b->m == 0);
}

I got a debug error on MSVC++ 2010.

I got a similar error when I tried the following code [My answer here] on MSVC++2010

2)

#include <cassert>
struct Struct {
    std::string String;
    int Int;
    bool k;
    // add add add
};

struct InStruct : Struct
{
   InStruct() : Struct() {}
};

int main()
{
   InStruct i;
   assert(i.k == 0);
}

Neither (1) nor (2) gave any such error on gcc/Clang which made me think if MSVC++2010 does not support C++03. I am not sure.

According to Michael Burr’s post [in C++03]

new B() – value-initializes B which zero-initializes all fields since its default ctor is compiler generated as opposed to user-defined.

The Standard says

To value-initialize an object of type Tmeans:

— if T is a class type (clause 9) with a user-declared constructor (12.1), then the default constructor for T is called (and the initialization is ill-formed if Thas no accessible default constructor);

…..

otherwise, the object is zero-initialized

From the first point if there is no user declared default constructor the compiler synthesized default constructor will be called which will zero initialize all the fields (according to last point).

So where am I wrong? Is my interpretation of value initialization correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:43:13+00:00Added an answer on May 17, 2026 at 8:43 pm

    Visual Studio has known bugs in all current versions (2005, 2008, 2010) where it doesn’t correctly implement value-initialization for non-POD types that don’t have a user declared constructor.

    By the language rules none of you asserts should fire but do exhibit the compiler issues. These are some of the bug reports, note that they are all closed or resolved as “Won’t Fix”.

    http://connect.microsoft.com/VisualStudio/feedback/details/564268/c-value-initialization

    http://connect.microsoft.com/VisualStudio/feedback/details/484295/vc-does-not-value-initialize-members-of-derived-classes-without-user-declared-constructor

    http://connect.microsoft.com/VisualStudio/feedback/details/100744/value-initialization-in-new-expression

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello again community, I posted a question just over an hour ago asking for
I have just asked this question an hour ago but with regards to IE8
I just installed nginx and php fastcgi about an hour ago, and after reading
I've just asked a question about an hour ago, while waiting for replies, I've
I'm pretty new to APEX ( well, just started using it ~an hour ago),
Somebody has posted an hour ago or so a question that was about the
I've just (about 1 hour ago) associated an Elastic IP to my instance at
I have a simple little table (just 8 fields) an hour ago I rebuilt
I have designed a form which was working fine until about an hour ago.
I posted up a question about an hour ago asking a regex question about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.