null [re: spec#]

Walter Bright newshound2 at digitalmars.com
Mon Nov 8 13:13:14 PST 2010


Jonathan M Davis wrote:
> How hard would it really be to insert code wherever a struct's init value is 
> used to default construct it either when the program starts up (for globals) or 
> right after it's declared (for locals)? If you could do that, then I don't see 
> why we couldn't have proper default constructors. All I can assume is that 
> adding that extra code to default construct structs would be painful change to 
> make to dmd, but perhaps there's something else that I'm missing. If that could 
> be done though, it would be a _huge_ improvement.

There are some severe problems with that approach. One of the largest is the 
possibility that the default constructor may fail (throw an exception). This has 
a vast impact on the design of things, and wrecks a lot of generic code that 
relies on being able to guarantee initialization success.


More information about the Digitalmars-d mailing list