D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6348 - Returning a struct from a C library function doesn't work correctly in 64 bit binaries
Summary: Returning a struct from a C library function doesn't work correctly in 64 bit...
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-19 11:52 UTC by siegelords_abode
Modified: 2022-12-09 13:23 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description siegelords_abode 2011-07-19 11:52:32 UTC
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 Ali Cehreli 2019-12-05 00:09:40 UTC
This example now works with at least 2.084.1 and 2.088.0. Please confirm and close.
Comment 2 RazvanN 2022-12-09 13:23:54 UTC
I can confirm that this is not reproducible.