Library writing - delegates or fp's?
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Tue Jul 18 07:29:59 PDT 2006
Carlos Santander wrote:
> Derek Parnell escribió:
>> Sure you can! How about this ...
>>
>>
>> import std.stdio;
>>
>> int delegate(int) increment;
>>
>> void main()
>> {
>> writefln( increment(1) );
>> writefln( incr(2) );
>> }
>>
>> int incr( int a )
>> {
>> return a + 1;
>> }
>>
>> static this()
>> {
>> increment = delegate int ( int a ) {return incr(a); };
>> }
>>
>> Would that do?
>>
>
> I thought the frame pointer would get lost and cause a segfault later on
> (see DFL events handling for an example.) Did that change with 0.161?
>
The frame pointer becomes invalid, but that is no problem since the
delegate is function-like and does not access the frame context (i.e.,
it's not a closure).
--
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-learn
mailing list