C++ Logo

std-discussion

Advanced search

Re: pointer to volatile, but no volatile object

From: Federico Kircheis <federico_at_[hidden]>
Date: Tue, 6 Jun 2023 07:02:45 +0200
On Mon, Jun 05, 2023 at 03:41:45PM -0700, Thiago Macieira via Std-Discussion wrote:
>On Monday, 5 June 2023 12:42:12 PDT Federico Kircheis via Std-Discussion
>wrote:
>> For what is worth, even a static_cast seems to hinder optimizations
>>
>> void foo(){
>> int a = -1;
>> *static_cast<volatile int*>(&a) = 42;
>> }
>
>The compilers probably think that "if you are trying to waste CPU cycles here,
>you must have a reason".

XD

The question is if the standard thinks the same too, or if this is
accepted practice by all compilers.

Received on 2023-06-06 05:02:52