If a standard document uses C code to describe std behavior, but that C code relies on UB, may an implementation do whatever they want?
-
-
My immediate thought: someone please go and find some UB in libopus
-
the problem with UB is that relying on it (in one place or another) is nearly inescapable in code which "actually does anything useful"...
-
No, that's a common misconception. It's mostly sloppiness, along with a small but nonzero amount of willful wrongness.
-
If you actually want to express wrapping signed arithmetic (rare that it's wanted) there are easy, zero-cost ways to express it without UB.
-
you mean using unsigned and casts?... maybe. I was thinking for example signed ((x<<31)>>31) and similar, (x/(1<<31)) may use a divide, ...
-
partial nvm: '/' wouldn't work here, would need ex: ((x>=0)?0:-1) or similar, but similar issue. saner IMO to just make all this be defined.
-
Use unsigned types whenever you're doing bitwise arithmetic. Then it's just -(x>>31).
-
That simplifies to a single SAR instruction on any decent compiler architecture.
- 11 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.