Struct default constructor - need some kind of solution for C++ interop
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Wed Sep 7 16:05:16 PDT 2016
On Wednesday, 7 September 2016 at 22:52:04 UTC, Walter Bright
wrote:
> On 9/7/2016 2:08 PM, deadalnix wrote:
>> It is clear at this point that structures with obligatory
>> initialization are
>> necessary. For C++ but not only.
>
> If not interfacing to C++, why?
>
I stated why.
> Is:
>
> if (resource != null)
> resource.destroy();
>
> v.s.:
>
> resource.destroy();
>
In some cases yes. Consider reference counting for instance.
> so onerous? It's one TST/JNE pair for a value loaded into a
> register anyway. And with a default constructor, there's all
> that code added to deal with the constructor failing and
> throwing.
>
One needs to construct anyway.
More information about the Digitalmars-d
mailing list