[OT] Move semantics in a nutshell
Timon Gehr
timon.gehr at gmx.ch
Mon Nov 10 16:53:28 UTC 2025
On 11/10/25 17:13, monkyyy wrote:
> On Monday, 10 November 2025 at 12:42:10 UTC, Timon Gehr wrote:
>> In your example you also had to think about "hmmm what are the
>> possible `T[]`. Actually you had to think about "hmmm what are the
>> possible combinations of `int`s and `T[]`s.
>
> That ubyte code was a static array
> ...
Sorry for not being clear, you are correct that "your example code" more
naturally refers to the `ubyte` example due to recency bias. I was here
talking about your earlier example with a `T[]`, where the point is even
a bit more obvious.
> A static 256 length array with a ubyte index has no "specific
> limitations on its bit pattern" if it fails its a os level failure and I
> couldn't operate anyway.
> ...
The simple fact is that you are able to relate types to execution
behavior. This is because the compiler produces binaries that are
related in a specific way to your source code. I.e., it establishes (or
at least aims to establish) very specific invariants on source code and
corresponding binaries. Undefined behavior is an example of weak
invariants, for a language without undefined behavior, these invariants
are stronger. Your workarounds against default behaviors that result in
crashes and/or UB are workarounds against weak invariants.
>> Look no further than encryption-based ransomware (e.g. EternalBlue
>> exploited by WannaCry and NotPetya/ExPetr). It's not a theoretical
>> scenario at all,
>
> Such encryption is **very** well defined, as is what version of rm -*
> will delete your harddrive.
> ...
The compiler produced an executable that allows an attacker to encrypt
or wipe the hard drive remotely when none of these capabilities were
spelled out in the source code of the program. It's a prime example of
undefined behavior in action that illustrates that the scenarios I
brought up are realistic in the context in which you had placed them.
More information about the Digitalmars-d
mailing list