3 ms·
>The problem is that C++ defines that every side-effect-free loop may be assumed by the compiler to terminate. That is, a loop that does not terminate is theref
by tester756 3y ago
>The problem is that C++ defines that every side-effect-free loop may be assumed by the compiler to terminate. That is, a loop that does not terminate is therefore undefined behavior. This is purely for compiler optimizations, once again treated as more important than correctness.
It is crazy that people decided to do it. It not only weird, but also wrong.
There's no such a thing like "side-effect-free" code.
There's always side-effect like CPU usage, temperature, mem usage, etc.
There is whole class of attacks based on those.
- dragonwriter 3y ago> There's always side-effect like CPU usage, temperature, mem usage, etc. If you are writing a loop in your code with no classic side effects hoping to regulate temperature, that’s probably a bad and unreliable design to start with, whether or not the compiler optimizes it away. If you read a temperature sensor to validate that the loop is doing the right thing and adjust frequency based on the result, its still a little crazy but its less completely insane and no longer free of classix side effects.
- tester756 3y agoAll I'm saying is that code doesn't have to perform stuff like prints, file write, http call in order to generate side effect You can run heavy computation and do not do anything with the result just in order to increase CPU usage, right? (which then should result in temp increase ;))
- tylerhou 3y agoThe C abstract machine isn't a physical machine, so temperature is not a side effect :)
- klodolph 3y ago> There's no such a thing like "side-effect-free" code. This kind of like “Ceci n'est pas une pipe.” In that it’s useful to remind people that there is no such thing as side-effect-free code, strictly speaking, but as soon as you remind people, you go back to talking about whether a particular piece of code has side effects. Someone points at object depicted in the painting and asks what it is, and you say “It’s a pipe.” Basically, to reason about code, it’s useful to ignore certain classes of side effects, most of the time.
- gpderetta 3y agoSide-effect is a Word of Power in the context of the standard with very specific meaning that doesn't include, for example, temperature increase. Even if you use it as a Control key replacement.
- layer8 3y agoWhat is meant are side effects as defined by the C abstract machine. It has no concept of CPU speed, temperature, etc.