Re: Calling C functions

2020-06-30 Thread Jacob Carlborg via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 12:22:15 UTC, Steven Schveighoffer wrote: (i.e. one cannot use extern(D) functions for C callbacks). I don't think that's a big issue. Honestly, I don't think it's an issue at all. BTW, the order of arguments is not the only thing. Variadic functions in D and

Re: Calling C functions

2020-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/20 3:00 AM, Kagamin wrote: On Monday, 29 June 2020 at 19:55:59 UTC, Steven Schveighoffer wrote: Yep, for sure. I'll file an issue. Anyone know why the calling convention would differ? It's easier to enforce left to right evaluation order this way: arguments are pushed to stack as

Re: Calling C functions

2020-06-30 Thread Kagamin via Digitalmars-d-learn
On Monday, 29 June 2020 at 19:55:59 UTC, Steven Schveighoffer wrote: Yep, for sure. I'll file an issue. Anyone know why the calling convention would differ? It's easier to enforce left to right evaluation order this way: arguments are pushed to stack as they are evaluated, which is pascal

Re: Calling C functions

2020-06-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/29/20 1:50 PM, Jacob Carlborg wrote: On Monday, 29 June 2020 at 16:34:33 UTC, Steven Schveighoffer wrote: Are you sure? On the ABI page [1] , it says "The extern (C) and extern (D) calling convention matches the C calling convention used by the supported C compiler on the host system."

Re: Calling C functions

2020-06-29 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 29 June 2020 at 16:34:33 UTC, Steven Schveighoffer wrote: Are you sure? On the ABI page [1] , it says "The extern (C) and extern (D) calling convention matches the C calling convention used by the supported C compiler on the host system." In that case the documentation is wrong.

Re: Calling C functions

2020-06-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/26/20 4:15 AM, Jacob Carlborg wrote: On Friday, 26 June 2020 at 00:30:22 UTC, Denis wrote: I have a two questions about calling C functions from D. (1) When passing a D callback to a C function, is there a way to write the code without having to prefix the callback declaration with

Re: Calling C functions

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 18:54, Denis wrote: OK, now this makes sense. I tested calling the same callback function directly from D: it compiled and worked correctly. So at least prefixing the callback function with `extern(C)` doesn't prevent the rest of the D program from calling it too. No, of

Re: Calling C functions

2020-06-26 Thread Denis via Digitalmars-d-learn
On Friday, 26 June 2020 at 08:15:27 UTC, Jacob Carlborg wrote: On Friday, 26 June 2020 at 00:30:22 UTC, Denis wrote: extern(C) void cfunc(void function(int)); extern(C) void dcallback(int x) {...} <-- Why extern(C)? cfunc(); Can this be rewritten, dropping the prefix from the

Re: Calling C functions

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 26 June 2020 at 00:30:22 UTC, Denis wrote: I have a two questions about calling C functions from D. (1) When passing a D callback to a C function, is there a way to write the code without having to prefix the callback declaration with "extern(C)"? It's not a big deal adding the

Re: Calling C functions

2010-12-09 Thread Steven Schveighoffer
On Thu, 09 Dec 2010 09:37:03 -0500, CrypticMetaphor crypticmetapho...@gmail.com wrote: I found this page that describes how to call c functions from D. I found this page that describes how: http://arsdnet.net/dtips/#cfunc on that page he uses gcc, and I use dmc, but I get different results.

Re: Calling C functions

2010-12-09 Thread CrypticMetaphor
On 12/9/2010 3:57 PM, Steven Schveighoffer wrote: On Thu, 09 Dec 2010 09:37:03 -0500, CrypticMetaphor crypticmetapho...@gmail.com wrote: I found this page that describes how to call c functions from D. I found this page that describes how: http://arsdnet.net/dtips/#cfunc on that page he uses

Re: Calling C functions

2010-12-09 Thread Steven Schveighoffer
On Thu, 09 Dec 2010 10:15:59 -0500, CrypticMetaphor crypticmetapho...@gmail.com wrote: On 12/9/2010 3:57 PM, Steven Schveighoffer wrote: On Thu, 09 Dec 2010 09:37:03 -0500, CrypticMetaphor crypticmetapho...@gmail.com wrote: I found this page that describes how to call c functions from D.

Re: Calling C functions

2010-12-09 Thread Andrej Mitrovic
I know I prefer using shared() when interfacing with C. I've tried using __gshared once when interfacing with C code. But I had crashes all the time, using shared instead made my app stable again. It might be related to the way the C code worked, since multiple threads were involved. Anyway..

Re: Calling C functions

2010-12-09 Thread Steven Schveighoffer
On Thu, 09 Dec 2010 11:38:00 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: I know I prefer using shared() when interfacing with C. I've tried using __gshared once when interfacing with C code. But I had crashes all the time, using shared instead made my app stable again. It might

Re: Calling C functions

2010-12-09 Thread CrypticMetaphor
On 12/9/2010 5:28 PM, Steven Schveighoffer wrote: On Thu, 09 Dec 2010 10:15:59 -0500, CrypticMetaphor crypticmetapho...@gmail.com wrote: On 12/9/2010 3:57 PM, Steven Schveighoffer wrote: On Thu, 09 Dec 2010 09:37:03 -0500, CrypticMetaphor crypticmetapho...@gmail.com wrote: I found this page

Re: Calling C functions

2010-12-09 Thread Andrej Mitrovic
On 12/9/10, Steven Schveighoffer schvei...@yahoo.com wrote: __gshared is unprotected sharing, and the type system is not aware that it is shared. Can you remember what specifically you were doing with the variable? My dev PC is in repairs right now so I don't have the code atm. It's a project

Re: Calling C functions

2010-12-09 Thread Steven Schveighoffer
On Thu, 09 Dec 2010 12:24:05 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 12/9/10, Steven Schveighoffer schvei...@yahoo.com wrote: __gshared is unprotected sharing, and the type system is not aware that it is shared. Can you remember what specifically you were doing with

Re: Calling C functions

2010-12-09 Thread Jesse Phillips
CrypticMetaphor Wrote: On 12/9/2010 5:28 PM, Steven Schveighoffer wrote: Yes please, and be sure to specify that it correctly does not compile on linux. http://d.puremagic.com/issues/enter_bug.cgi -Steve Alright then! I submitted a my first bug report and added __gshared in front

Re: Calling C functions

2010-12-09 Thread Adam Ruppe
I almost forgot I wrote that dtips page! Thanks for bringing it up. I just updated it to include a brief note on __gshared. The rest of it should still work, though. Calling C functions is pretty easy.

Re: Calling C functions

2010-12-09 Thread CrypticMetaphor
On 12/9/2010 10:04 PM, Jesse Phillips wrote: CrypticMetaphor Wrote: It is a linker bug, so Oplink is at fault. What is the bug number you submitted? bug number: 5337 http://d.puremagic.com/issues/show_bug.cgi?id=5337