DIP62: Volatile type qualifier for unoptimizable variables in embedded programming
Iain Buclaw via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 15 12:23:27 PDT 2014
On 15 July 2014 19:38, Meta via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Tuesday, 15 July 2014 at 18:30:11 UTC, Johannes Pfau wrote:
>>
>> No, this doesn't work with Volatile!:
>>
>> struct A
>> {
>> private int _val;
>> int read(){ return val+val };
>> int read(bool volatile)() { auto tmp = val; return tmp*tmp; };
>> }
>
>
> struct A
> {
> private int _val;
> int read(bool volatile)()
> {
> static if (volatile)
> {
>
> auto tmp = val; return tmp*tmp;
> }
> else
> {
> return val+val;
> }
> };
> }
>
> And you are no worse off than before. This template can only generate 2
> possible functions, and the instantiations are also cached so as far as I
> know, there's no code bloat.
>
Worse, there's no code because the compiler optimises everything away!
More information about the Digitalmars-d
mailing list