www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8810] New: struct not returned properly from extern (C) functions

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: epi atari8.info


--- Comment #0 from Adrian Matoga <epi 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: -------
Oct 12 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8810


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim maxim-fomin.ru> 2012-10-12 23:25:40 PDT
---
Looks like issue 5570

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 12 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8810


Adrian Matoga <epi atari8.info> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #2 from Adrian Matoga <epi atari8.info> 2012-10-12 23:32:04 PDT ---
Indeed. Sorry, search didn't point me to that one.

*** This issue has been marked as a duplicate of issue 5570 ***

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