Address of parameterless ref function
Timon Gehr
timon.gehr at gmx.ch
Sun Apr 10 01:05:38 PDT 2011
I think I get it now. The example is actually invalid code accepted by the dmd
frontend. It allows a pointer of type "int function() ref" to be implicitly
converted to "int function()". Internally the "int function() ref" returns a
pointer to an integer. Both integers and pointers are returned the same way (EAX
register AFAIK). Therefore, after the assignment f=&g, the function f=&g is
treated as if it was a function that returns an int in the EAX register, while
actually it returns a reference to an int in the EAX register. The EAX contents of
the EAX register are just interpreted differently. That is how the implicit
reinterpret-cast from "int ref" to "int" takes place.
I am filing a bug report.
BTW: You can actually declare a variable of type "int function() ref" by the means
of the auto keyword, but not in any other way. I assume this is a bug too.
More information about the Digitalmars-d
mailing list