For example:
char *p=new char[100];
Must the character array pointed to by p be initialized to zeroes per the C++ standard? Or, is this behavior completely compiler dependant?
gcc seems to call the default constructor on each character, which of course initializes them to zero. Visual C++ 2010 does not.
No, POD types are left uninitialised when they are created by
new. You could value-initialise them to zero if you want:This is specified by the standard:
Your other observation:
It shouldn’t do – especially as
chardoesn’t have a constructor. If you replace it with a type with a default constructor, then that will be called for each element.I get the following disassembly, with no sign of any initialisation: