trusted purity?
monarch_dodra
monarchdodra at gmail.com
Mon Apr 29 22:42:55 PDT 2013
On Monday, 29 April 2013 at 20:51:50 UTC, Walter Bright wrote:
> On 4/29/2013 1:03 PM, monarch_dodra wrote:
>> On Monday, 29 April 2013 at 18:34:46 UTC, Walter Bright wrote:
>>> On 4/29/2013 10:19 AM, monarch_dodra wrote:
>>>> I'm getting strange behavior trying to cast to pure. This is
>>>> my
>>>> test program:
>>>
>>> You're casting a C function to a D function. This will cause
>>> crashes.
>>
>> OK, so say I have a documented pure C function, how do I call
>> it from a pure
>> scope? You say, take the address and cast it, but not if it's
>> C...
>
> extern (C) {
> int foo(int);
> }
>
> extern (C) {
> pure int function(int) fp_pure_t;
> }
>
> ...
> cast(fp_pure_t)(&foo)
Thanks. That (kinda) worked. I just had to add an alias, because
the compiler was complaining about: "Error: fp_pure_t is used as
a type"
This works though:
//====
extern (C) {
int foo(int);
}
extern (C) {
alias pure int function(int) fp_pure_t;
}
...
cast(fp_pure_t)(&foo)
//====
That works.
More information about the Digitalmars-d
mailing list