D struct with String type accessing from Python

Ali Çehreli acehreli at yahoo.com
Tue Dec 27 17:04:03 UTC 2022


On 12/26/22 22:42, cc wrote:

 > Why does returning a
 > struct, or sending a D string via an out parameter, work here, but
 > simply returning a D string does not?

I don't know C# to be sure but it must be ABI related. The way D passes 
returned objects must be different from what C# expects. (There is no 
extern(C#) to rely on here. ;) )

 > static struct DString {
 >      size_t length;

[...]

 > [StructLayout(LayoutKind.Sequential, Size=16, Pack=1)]
 > public struct DString {
 >      public ulong length;

[...]

Apparently that works in your case but D's size_t will be 32 bits on a 
32-bit build. I checked: C#'s ulong is always 64 bits.

Ali



More information about the Digitalmars-d mailing list