Default initializers (or: win32 bindings' struct sizes)
Lionello Lunesu
lio at lunesu.remove.com
Wed Jan 17 04:11:27 PST 2007
Hi,
Many structures in the win32 bindings project on dsource set their size
using D's default initializer:
#struct STARTUPINFOA {
# DWORD cb = STARTUPINFOA.sizeof;
# LPSTR lpReserved;
#//...
#}
This does save some typing when in Win32 projects, but results in
unexpected linker errors (dmd 1.0):
Error 42: Symbol Undefined _D5win327winbase12STARTUPINFOA6__initZ
These errors can only be solved by
1) adding the appropriate .d files from the win32 folder on the command
line, or
2) building a win32.lib (containing all initializers) and linking to it;
3) commenting out the "= ...sizeof;" part.
All of which seem inappropriate for a bindings project that merely
contains translated headers.
One solution might be to add a version(..) around all default
initializer, providing both an initialized and uninitialized version.
Another, far better, solution would be to change DMD: the compiler knows
the initializer and can safely inline it. What's more, the there are no
linker errors for the default built-in initializers:
struct S { int s; } // no linker error
struct D { int d=0; } // linker error!
The linking error occurs even with the -O -release -inline flags.
Why does DMD (I don't know about GDC) require that __init symbol for
custom initializers and not for the default ones? Is there any chance
that this requirement will be dropped?
L.
More information about the Digitalmars-d
mailing list