http://d.puremagic.com/issues/show_bug.cgi?id=8810

           Summary: struct not returned properly from extern (C) functions
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: e...@atari8.info


--- Comment #0 from Adrian Matoga <e...@atari8.info> 2012-10-12 23:09:41 PDT ---
// 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)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to