Thread overview | |||||
---|---|---|---|---|---|
|
January 06, 2016 link to C function whose name is a D keyword | ||||
---|---|---|---|---|
| ||||
Hello, Is there a way from D to do this, without writing a C wrapper? e.g. I want to call a C function named 'try'. /* C prototype */ int try(int x); //D that doesn't work: extern(C) int try(int x); |
January 06, 2016 Re: link to C function whose name is a D keyword | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carl Sturtivant | On Wednesday, 6 January 2016 at 15:41:27 UTC, Carl Sturtivant wrote:
> //D that doesn't work:
> extern(C) int try(int x);
Try:
pragma(mangle, "try")
extern(C) int try_(int x);
then call it with the udnerscore in D, the linker should tie it up thanks to the pragma.
|
January 06, 2016 Re: link to C function whose name is a D keyword | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Wednesday, 6 January 2016 at 15:42:34 UTC, Adam D. Ruppe wrote:
> On Wednesday, 6 January 2016 at 15:41:27 UTC, Carl Sturtivant wrote:
>> //D that doesn't work:
>> extern(C) int try(int x);
>
> Try:
>
> pragma(mangle, "try")
> extern(C) int try_(int x);
>
> then call it with the udnerscore in D, the linker should tie it up thanks to the pragma.
Very handy! Thank you.
|
Copyright © 1999-2021 by the D Language Foundation