Re: g++ 3.4.5 doesn't zero-initialize
"Alf P. Steinbach" <alfps@start.no>
..
Grr.
What's wrong with this code?
struct WndClassEx: WNDCLASSEX
{
WndClassEx(
cppx::WideString const& name,
Params const& params
)
: WNDCLASSEX()
{
cbSize = sizeof( WNDCLASSEX );
style = params.style();
lpfnWndProc = &DefWindowProc;
hInstance = params.module();
hCursor = ::LoadCursor( 0, IDC_ARROW );
hbrBackground = reinterpret_cast<HBRUSH>( COLOR_BTNFACE +
1 );
lpszClassName = name.cStr();
}
WndClassEx const* ptr() const
{
return this;
}
};
Answer: nothing in particular, at least when one knows that it's just a
little local helper class where 'name' arg has lifetime guaranteed to be
enough.
The problem is you build on working 'value-init' that is known to have
real-world problems.
But MinGW g++ doesn't zero-initialize the WNDCLASSEX as it should (this is
a plain struct with no constructor, provided by the Windows API).
Argh!
I knew old MSVC doesn't always zero-initialize /arrays/ when told to.
But I didn't know that g++ doesn't zero-initialize /structs/ when told to.
Does that version claim support for C++03? IIRC C++98 did not have the value
init for structs, and I guess the 3.x versions were about the turning point.
Even if it did claim TC1 I tend to doubt fair implementation in the first
year.
Honestly, the calendar is 2009 by now, but I'd not rely in value init even
of current compielrs -- at least without first checking the version and
include some defense cludges in code should it migrate away...
And by the way, the gdb debugger is driving me crazy.
Too bad -- if doing windows, why not use the windows toolset? I doubt gdb
will ever come close to Visual's... If your prog is portable, it will go in
VS express, if not -- what is the wisdom behind locking into a compiler
that is poorly supported on the target platform?
And if porting win code away, why to an archaic version of gcc instead of a
current?
Ignoring breakpoints and telling me the source code for some stack frame
is at arbitrary location in arbitrary file. And yes, optimizations turned
off, which is another annoyance, since g++ needs optimizations on to e.g.
warn about uninitialized things.
And inside ddd it crashes on all kind of ocasions, sometimes gets confused
of the objects to show, etc...