← Back to index
|
Original Bugzilla link
Bug 8810 – struct not returned properly from extern (C) functions
Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-10-12T23:09:00Z
Last change time
2012-10-12T23:32:04Z
Assigned to
nobody
Creator
adrian
Comments
Comment #0
by adrian — 2012-10-12T23:09:41Z
// foo.c typedef struct { unsigned bar; unsigned baz; } Foo; Foo setFoo(unsigned a, unsigned b) { Foo foo; foo.bar = a; foo.baz = b; } void setFooByPointer(unsigned a, unsigned b, Foo *pFoo) { pFoo->bar = a; pFoo->baz = b; } // strukt.d import std.stdio; struct Foo { uint bar; uint baz; } extern (C) Foo setFoo(uint a, uint b); extern (C) void setFooByPointer(uint a, uint b, Foo* pFoo); void main() { Foo foo; setFooByPointer(31337, 42, &foo); writeln(foo); foo = setFoo(31337, 42); writeln(foo); } // build $ dmd -c strukt.d -ofstrukt.o $ gcc -c foo.c -o foo.o $ dmd foo.o strukt.o -ofstrukt // run $ ./strukt Foo(31337, 42) Foo(42, 0) // expected: Foo(31337, 42) Foo(31337, 42)
Comment #1
by maxim — 2012-10-12T23:25:40Z
Looks like issue 5570
Comment #2
by adrian — 2012-10-12T23:32:04Z
Indeed. Sorry, search didn't point me to that one. *** This issue has been marked as a duplicate of issue 5570 ***