Accessing peripheral registers - the next version

Timo Sintonen via D.gnu d.gnu at puremagic.com
Wed Aug 31 12:06:37 PDT 2016


On Wednesday, 31 August 2016 at 10:12:21 UTC, Johannes Pfau wrote:

>> There was @disable this(this)
>> This prevents to use a location as argument to a function, 
>> like:
>> print(timer.count). Is there any reason to have this line or 
>> not?
>
> I guess timer is a (enum) pointer to a struct and count is a 
> Volatile!T
> field in that struct?
Yes

> But then timer.count does not return a address, it returns the 
> value of
> count? Unless of course print(X) takes its argument by ref or 
> alias.
I want to use them just by value.

>
> The reason for @disable this(this) is to disable copying of the 
> struct.
> The compiler otherwise accesses T raw in a 'non-volatile' way 
> when
> copying the value. In D we can only have a postblit function, 
> but we
> cannot reimplement the copying. opAssign can only be used in 
> some cases:
>     Foo f;
>     auto f2 = Foo();
>     auto f3 = f2;
>     f = Foo();
>     f = f2;
>
> Only the last two lines call opAssign. So "auto f3 = f2" could 
> copy a Volatile!T in a non-volatile way. This is the reason for 
> @disable this(this), AFAIK.
>
I think I somehow get the point even if I do not fully understand 
the explanation.
But it is too restrictive if I always need to have a getter 
function or assign the value first to a temporary variable to use 
the value in a function call.

Anyway, I think it is a gdc bug that the error message comes from 
the called function that has nothing to do with this. The error 
should show the function call where the disabled copy operation 
is.



More information about the D.gnu mailing list