Converting function pointers to delegates

Artur Skawina art.08.09 at gmail.com
Tue Apr 15 05:04:43 PDT 2014


On 04/15/14 13:30, Andrej Mitrovic wrote:
> On 4/15/14, Artur Skawina <art.08.09 at gmail.com> wrote:
>> It *is* true. Classes are /reference types/, not references to classes.
> 
> I meant the part where he said you can't cast a reference to a pointer. You can.

He obviously meant that you can't get a pointer to the object, that the
reference points to, just by casting and w/o address-of.

   int* f(ref int r) { return cast(int*)r; }

   void main() {   
      int a = 42;

      import std.stdio;
      writeln(&a);
      writeln(f(a));
   }

Yes, this will compile, and, yes, you can "cast a reference to a pointer",
but this does not mean that you will get a pointer to 'a'.

The D situation wrt to refs and classes is bad enough; saying that you
"can cast a reference to a pointer" will only confuse people. 

artur


More information about the Digitalmars-d-learn mailing list