C++ Logo


Advanced search

Re: [std-proposals] Every variable is volatile, everything is laundered, no optimisation

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 26 Aug 2023 10:11:05 -0700
On Saturday, 26 August 2023 03:31:17 PDT Frederick Virchanza Gotham via Std-
Proposals wrote:
> NewMicroscope obj;
> IXYZInterface &inter = obj.GetInterface();
> IXYZComHandler &com =
> *static_cast<IXYZComHandler*>(static_cast<void*>(static_cast<char*>(static_c
> ast<void*>(&inter)) + 8u));
> The code was tested and working before I sent it to them. Is it Ideal to be
> sending code like this out to customers? No it's not. But I live in the
> real world.

This is a very good counter-example of allowing such a feature. Your patch job
is extremely non-portable: it depends on the size of pointers (it wouldn't
work on 32- bs 64-bit ABIs), it depends on how the compiler is allocating base
sub-objects in the object (it wouldn't work with other compilers). And
obviously depends on your hierarchy of classes, so it's not obvious how to use
it elsewhere either.

If your fix is dependent on a single compiler's behaviour, why do we care about
making a standard change?

In fact, how *would* a standard change have helped you? How would allowing a
launder there have helped you find that 8-byte displacement?

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-08-26 17:11:07