Given two functions, function A which returns a struct and function B which accepts a struct, writing B(A()) corrupts the passed struct if both A and B have the C calling convention on 64 bit systems. This works fine on 32 bit LDC and with DMD 1.053.
import tango.io.Stdout;
extern (C)
{
struct Color
{
float r,g,b,a;
}
Color C_GetColor(float r, float g, float b, float a)
{
return Color(r,g,b,a);
}
void C_PrintColor(Color color)
{
Stdout.formatln("{} {} {} {}", color.r, color.g, color.b, color.a);
}
}
Color GetColor(float r, float g, float b, float a)
{
return Color(r,g,b,a);
}
void PrintColor(Color color)
{
Stdout.formatln("{} {} {} {}", color.r, color.g, color.b, color.a);
}
void main()
{
//Prints # # 1.00 2.00
//where # is some random number
C_PrintColor(C_GetColor(1, 2, 3, 4));
Color color = C_GetColor(1, 2, 3, 4);
//Prints 1.00 2.00 3.00 4.00
C_PrintColor(color);
//Prints 1.00 2.00 3.00 4.00
PrintColor(GetColor(1, 2, 3, 4));
//Prints 1.00 2.00 3.00 4.00
PrintColor(C_GetColor(1, 2, 3, 4));
//Prints 1.00 2.00 3.00 4.00
C_PrintColor(GetColor(1, 2, 3, 4));
}