pointers, functions, and uniform call syntax

Carl Sturtivant sturtivant at gmail.com
Mon Sep 3 08:47:13 PDT 2012


>> ----
>> struct S
>> {
>>  void foo();
>> }
>> void bar(S);
>>
>> void main()
>> {
>>  auto r = new S;
>>  r.foo();
>>  bar(r);  //derp
>>  r.bar(); //derp
>> };
>> ----
>
> bar(r) would need D to support an implied conversion of S* to S 
> (or to ref S with bar having a reference parameter if you 
> wanted to avoid copying), for this to work.
>
> Converting S* to ref S (without copying) is an interesting idea 
> for D. I wonder what those close to the definition of D and the 
> compiler think of it.

It seems that the following discussion is relevant to the above.

"Why can't we have reference variables"
http://forum.dlang.org/thread/ruwapnhkuvozitefzplt@forum.dlang.org

A conservative viewpoint is that converting S* to ref S at the 
point of call requires that the pointer is valid (because 
non-pointer variables always work properly as a part of the way 
the language is defined), and there's no way that the compiler 
can simply verify that this is so. Therefore, such a conversion 
should be the programmers responsibility and not be done 
implicitly.

Carl.



More information about the Digitalmars-d mailing list