[Issue 19179] extern(C++) small-struct by-val uses wrong ABI

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Sep 10 02:50:59 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19179

Jack <look.at.me.pee.please at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |look.at.me.pee.please at gmail
                   |                            |.com

--- Comment #2 from Jack <look.at.me.pee.please at gmail.com> ---

Can't reproduce with your example, I've come across something similar in the
past though. If you swap your struct with this one:


struct SmallStruct {
        int x, y;

        SmallStruct()
        {
                x = 10;
                y = 20;
        }
};

static_assert(!std::is_pod<SmallStruct>::value, ""); // not a POD, your other
struct is a POD though


the D version will be POD though. But since you can't have a default
constructor in D, you have to use another method to make it not POD. That is
give it a destructor "~this()" or a copy constructor "this(this)".

Windows treats structs that aren't POD differently if they are less than 8
bytes. That's the root of the problem.

A solution would be to add an attribute "@NotPOD struct blah { }" or something,
rather than having to put an empty constructor. Not exactly something that is
easy to notify the user of if this inconsistency exists.

--


More information about the Digitalmars-d-bugs mailing list