digitalmars.D - Interfacing with C - div
- Juliano Ravasi Ferraz (17/17) Jul 03 2004 Hi,
- Ben Hinkle (5/28) Jul 05 2004 I don't know why but it works for me when I add an extra int field to di...
- Ant (4/32) Jul 05 2004 oh,oh... this looks like the overload bug or the lookup rules in action.
- Juliano Ravasi Ferraz (5/8) Jul 05 2004 Wow! Really worked with a third int... sure it is odd...
- Walter (6/33) Jul 05 2004 div_t:
Hi, I've been trying to do a simple C interface, but failed miserably until now: extern (C) { struct div_t { int quot, rem; } div_t div(int numer, int denom); } int main() { div_t q = div(35, 10); printf("%d/%d\n", q.quot, q.rem); return 0; } Since my glibc doesn't have debuging symbols, the only useful thing that gdb reports is that it bailed out inside the div() call. Does someone know where did I fail? My host is a Linux i686 2.6.6, glibc 2.3.2. Regards, Juliano.
Jul 03 2004
Juliano Ravasi Ferraz wrote:Hi, I've been trying to do a simple C interface, but failed miserably until now: extern (C) { struct div_t { int quot, rem; } div_t div(int numer, int denom); } int main() { div_t q = div(35, 10); printf("%d/%d\n", q.quot, q.rem); return 0; } Since my glibc doesn't have debuging symbols, the only useful thing that gdb reports is that it bailed out inside the div() call. Does someone know where did I fail? My host is a Linux i686 2.6.6, glibc 2.3.2. Regards, Juliano.I don't know why but it works for me when I add an extra int field to div_t: struct div_t { int quot, rem, foo; } very odd. -Ben
Jul 05 2004
In article <ccbpb8$29d6$1 digitaldaemon.com>, Ben Hinkle says...Juliano Ravasi Ferraz wrote:oh,oh... this looks like the overload bug or the lookup rules in action. If I had phobos here I would check other declarations of div... AntHi, I've been trying to do a simple C interface, but failed miserably until now: extern (C) { struct div_t { int quot, rem; } div_t div(int numer, int denom); } int main() { div_t q = div(35, 10); printf("%d/%d\n", q.quot, q.rem); return 0; } Since my glibc doesn't have debuging symbols, the only useful thing that gdb reports is that it bailed out inside the div() call. Does someone know where did I fail? My host is a Linux i686 2.6.6, glibc 2.3.2. Regards, Juliano.I don't know why but it works for me when I add an extra int field to div_t: struct div_t { int quot, rem, foo; } very odd. -Ben
Jul 05 2004
Ben Hinkle wrote:I don't know why but it works for me when I add an extra int field to div_t: struct div_t { int quot, rem, foo; } very odd.Wow! Really worked with a third int... sure it is odd... Thanks! Regards, Juliano.
Jul 05 2004
"Ben Hinkle" <bhinkle4 juno.com> wrote in message news:ccbpb8$29d6$1 digitaldaemon.com...Juliano Ravasi Ferraz wrote:div_t:Hi, I've been trying to do a simple C interface, but failed miserably until now: extern (C) { struct div_t { int quot, rem; } div_t div(int numer, int denom); } int main() { div_t q = div(35, 10); printf("%d/%d\n", q.quot, q.rem); return 0; } Since my glibc doesn't have debuging symbols, the only useful thing that gdb reports is that it bailed out inside the div() call. Does someone know where did I fail? My host is a Linux i686 2.6.6, glibc 2.3.2. Regards, Juliano.I don't know why but it works for me when I add an extra int field tostruct div_t { int quot, rem, foo; } very odd.D returns structs that are 8 bytes long in EDX,EAX. Longer ones are returned on the stack. Perhaps gcc uses a different convention. An obj2asm on the code will tell the tale.
Jul 05 2004