Functions, intrinsics, flexibility

Alex Rønne Petersen xtzgzorex at gmail.com
Mon Sep 19 11:32:31 PDT 2011


On 18-09-2011 21:47, Timon Gehr wrote:
> On 09/18/2011 08:57 PM, bearophile wrote:
>> I don't know what is the right design in this case. Intrinsics are
>> useful because they sometimes give more performance, but normal
>> functions are sometimes more handy because they allow more
>> flexibility, like taking their address ("first class functions"):
>>
>>
>> import std.math;
>> void main() {
>> auto a = [&sin,&cos];
>> }
>>
>>
>> DMD 2.055:
>>
>> OPTLINK (R) for Win32 Release 8.00.12
>> Copyright (C) Digital Mars 1989-2010 All rights reserved.
>> http://www.digitalmars.com/ctg/optlink.html
>> test.obj(test)
>> Error 42: Symbol Undefined _D3std4math3sinFNaNbNfeZe
>> test.obj(test)
>> Error 42: Symbol Undefined _D3std4math3cosFNaNbNfeZe
>>
>> Isn't it possible to find some middle way that allows me to use
>> std.math.sin as true functions, while keeping the advantages of
>> intrinsics?
>>
>> (Currently I define wrapper functions like mysin, mycos, etc).
>>
>> Bye,
>> bearophile
>
> +1, the compiler should just rewrite your example so that it 'just
> works'. An alternative to your fix is to create an object file that
> contains the appropriate symbols.

You could write a wrapper function that calls the intrinsic, but I 
suppose this defeats the purpose...

- Alex


More information about the Digitalmars-d-learn mailing list