Comparing function pointers
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 11 10:48:29 PST 2015
On Wed, 11 Feb 2015 18:40:03 +0000, Freddy wrote:
> ----
> import std.stdio;
>
> auto test1(){
> void testFunc(){
> }
> return &testFunc;
> }
>
> auto test2(){
> uint a;
> void testFunc(){
> a=1;
> }
> return &testFunc;
> }
>
> void main(){
> writeln(test1()==test1());//true writeln(test2()==test2());//false
> }
> ----
> Is the intended behavior?
second thing is not a function, it's a closure (fat pointer internally).
each time you calling `test2()`, you creating new closure. so yes, this
is intended behavior.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150211/b74c8fdc/attachment.sig>
More information about the Digitalmars-d-learn
mailing list