digitalmars.D.learn - Help with C struct by value on OSX 64bits
- Johan Hernandez (49/49) Apr 25 2012 Hi. I'm having trouble calling a C function passing a structure
- simendsjo (3/6) Apr 25 2012 Could be this one: http://d.puremagic.com/issues/show_bug.cgi?id=5570
- Johan Hernandez (3/5) Apr 25 2012 Thank you for your response.
- simendsjo (4/8) Apr 25 2012 I agree. Let's hope it gets fixed now that it's confirmed on OSX too.
- Jacob Carlborg (5/9) Apr 25 2012 Compile as a 32bit binary. For DMD add "-m32" do the flags. For gcc add
- Johan Hernandez (4/6) Apr 26 2012 Thanks Jacob, that worked!!!
Hi. I'm having trouble calling a C function passing a structure by value, printing a member and getting it back in D but I must be doing something wrong. I have a C file called native.c that defines a function called 'filter' taking a buf_t structure, I compile it using GCC to native.o. From D, I use extern(C) to access the 'filter' function defined in native.o. app: native.o dmd -ofbin/app app.d native.o chmod +x bin/app bin/./app native.o: native.c gcc -c native.c -o native.o import std.stdio; extern(C) struct buf_t { void* base; size_t len; } extern(C) buf_t filter(const buf_t value); void main() { buf_t buf; buf.len = 10; auto r = filter(buf); writefln("D: len %d", r.len); } ***native.c*** #include <sys/types.h> #include <stdio.h> typedef struct { void* base; size_t len; } buf_t; buf_t filter(buf_t value) { printf("C: len: %zu\n", value.len); return value; } ***The output*** C: len: 140734905718328 D: len 0 "len" should be 10 in both cases. What am I doing wrong? I'm using: OS: Mac OSX Lion, 64bits. D compiler: DMD64 D Compiler v2.058 C compiler: gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00) Thanks, Johan
Apr 25 2012
On Wed, 25 Apr 2012 09:57:39 +0200, Johan Hernandez <thepumpkin1979 gmail.com> wrote:Hi. I'm having trouble calling a C function passing a structure by value, printing a member and getting it back in D but I must be doing something wrong.Could be this one: http://d.puremagic.com/issues/show_bug.cgi?id=5570
Apr 25 2012
On Wednesday, 25 April 2012 at 08:38:02 UTC, simendsjo wrote:Could be this one: http://d.puremagic.com/issues/show_bug.cgi?id=5570Thank you for your response. It's a huge issue :(
Apr 25 2012
On Wed, 25 Apr 2012 20:36:31 +0200, Johan Hernandez <thepumpkin1979 gmail.com> wrote:On Wednesday, 25 April 2012 at 08:38:02 UTC, simendsjo wrote:I agree. Let's hope it gets fixed now that it's confirmed on OSX too. You could use the voting system in bugzilla to give the issue more focus.Could be this one: http://d.puremagic.com/issues/show_bug.cgi?id=5570Thank you for your response. It's a huge issue :(
Apr 25 2012
On 2012-04-25 20:36, Johan Hernandez wrote:On Wednesday, 25 April 2012 at 08:38:02 UTC, simendsjo wrote:Compile as a 32bit binary. For DMD add "-m32" do the flags. For gcc add "-arch i386". -- /Jacob CarlborgCould be this one: http://d.puremagic.com/issues/show_bug.cgi?id=5570Thank you for your response. It's a huge issue :(
Apr 25 2012
On Wednesday, 25 April 2012 at 19:43:27 UTC, Jacob Carlborg wrote:Compile as a 32bit binary. For DMD add "-m32" do the flags. For gcc add "-arch i386".Thanks Jacob, that worked!!! simendsjo: I upvoted and commented the same day bro.
Apr 26 2012