Bug 6348 – Returning a struct from a C library function doesn't work correctly in 64 bit binaries
Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2011-07-19T11:52:32Z
Last change time
2022-12-09T13:23:54Z
Assigned to
No Owner
Creator
siegelords_abode
Comments
Comment #0 by siegelords_abode — 2011-07-19T11:52:32Z
Create two files with these contents.
File: test.c
typedef struct
{
float r,g,b,a;
} COLOR;
COLOR makecol(float r, float g, float b, float a)
{
COLOR ret;
ret.r = r;
ret.g = g;
ret.b = b;
ret.a = a;
return ret;
}
File: test.d
import std.stdio;
struct COLOR
{
float r,g,b,a;
}
extern (C) COLOR makecol(float r, float g, float b, float a);
void main()
{
auto col = makecol(1, 0.5, 1, 0.5);
writefln("%s, %s, %s, %s", col.r, col.g, col.b, col.a);
}
Now compile the whole mess and test:
gcc -c test.c && ar -r test.a test.o
dmd test.d test.a
./test
The expected output is "1, 0.5, 1, 0.5" but actually it output something completely different ("0, 0, 0, 0" on my system). This happens with both dmd 2.054 and 1.069.
Perhaps this bug is related to 5570?
Comment #1 by acehreli — 2019-12-05T00:09:40Z
This example now works with at least 2.084.1 and 2.088.0. Please confirm and close.
Comment #2 by razvan.nitu1305 — 2022-12-09T13:23:54Z