Re: Basics of calling C from D

2014-06-12 Thread Mike Parker via Digitalmars-d-learn
On 6/12/2014 12:17 AM, Colin wrote: So a find an replace will do that for you quite easily. Other things like structs and typedefs are a bit more difficult to do with a find replace. All the info you need is here anyway: wiki.dlang.org/Bind_D_to_C And here:

Basics of calling C from D

2014-06-11 Thread belkin via Digitalmars-d-learn
Example: I have this C function that is compiled into a library //File: factorial.h int factorial(int n); //File: factorial.c #include factorial.h int factorial(int n) { if(n!=1) return n*factorial(n-1); } Question: How do I use it from D?

Re: Basics of calling C from D

2014-06-11 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Example: I have this C function that is compiled into a library //File: factorial.h int factorial(int n); //File: factorial.c #include factorial.h int factorial(int n) { if(n!=1) return n*factorial(n-1); } Question: How do I

Re: Basics of calling C from D

2014-06-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Question: How do I use it from D? Write the prototype in your D file with extern(C): extern(C) int factorial(int n); then just call the function normally in D. Make sure you include all the C object files when you compile the D

Re: Basics of calling C from D

2014-06-11 Thread simendsjo via Digitalmars-d-learn
On 06/11/2014 03:54 PM, Adam D. Ruppe wrote: On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Question: How do I use it from D? Write the prototype in your D file with extern(C): extern(C) int factorial(int n); then just call the function normally in D. Make sure you include all

Re: Basics of calling C from D

2014-06-11 Thread belkin via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 14:02:08 UTC, John Colvin wrote: On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Example: I have this C function that is compiled into a library //File: factorial.h int factorial(int n); //File: factorial.c #include factorial.h int factorial(int n) {

Re: Basics of calling C from D

2014-06-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 14:11:04 UTC, simendsjo wrote: I believe the correct answer should be Buy my book!. ah, of course! I should just make a .sig file lol http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book chapter 4 talks about this kind of thing :P

Re: Basics of calling C from D

2014-06-11 Thread belkin via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 14:22:51 UTC, Adam D. Ruppe wrote: On Wednesday, 11 June 2014 at 14:11:04 UTC, simendsjo wrote: I believe the correct answer should be Buy my book!. ah, of course! I should just make a .sig file lol

Re: Basics of calling C from D

2014-06-11 Thread simendsjo via Digitalmars-d-learn
On 06/11/2014 04:22 PM, Adam D. Ruppe wrote: On Wednesday, 11 June 2014 at 14:11:04 UTC, simendsjo wrote: I believe the correct answer should be Buy my book!. ah, of course! I should just make a .sig file lol http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

Re: Basics of calling C from D

2014-06-11 Thread Colin via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 14:28:49 UTC, belkin wrote: On Wednesday, 11 June 2014 at 14:02:08 UTC, John Colvin wrote: On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Example: I have this C function that is compiled into a library //File: factorial.h int factorial(int n);

Re: Basics of calling C from D

2014-06-11 Thread Colin via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 15:14:19 UTC, Colin wrote: On Wednesday, 11 June 2014 at 14:28:49 UTC, belkin wrote: On Wednesday, 11 June 2014 at 14:02:08 UTC, John Colvin wrote: On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Example: I have this C function that is compiled into a

Re: Basics of calling C from D

2014-06-11 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 14:28:49 UTC, belkin wrote: On Wednesday, 11 June 2014 at 14:02:08 UTC, John Colvin wrote: On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Example: I have this C function that is compiled into a library //File: factorial.h int factorial(int n);

Re: Basics of calling C from D

2014-06-11 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 11/06/14 16:22, Adam D. Ruppe via Digitalmars-d-learn wrote: On Wednesday, 11 June 2014 at 14:11:04 UTC, simendsjo wrote: I believe the correct answer should be Buy my book!. ah, of course! I should just make a .sig file lol

Re: Basics of calling C from D

2014-06-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 14:45:22 UTC, simendsjo wrote: I must say I really like your writing-style as well as the down-to-earth and precise and concise presentation of the material. So kudos to you! thanks, don't forget to tell that to amazon review readers too :P Really looking