3 ms·
> They intentionally broke bitwise operators on volatiles because they wanted to be impose their atomic religion everywhere. Could you elaborate on this?
by Sniffnoy 15d ago
> They intentionally broke bitwise operators on volatiles because they wanted to be impose their atomic religion everywhere.
Could you elaborate on this?
- aw1621107 15d ago"broke" is arguably an overstatement. C++20 deprecated some (most?) operations on volatile variables [0] in part because they can misleadingly imply an atomic operation: > volatile external modifications are only truly meaningful for loads and stores. Other read-modify-write operations imply touching the volatile object more than once per byte because that’s fundamentally how hardware works. Even atomic instructions (remember: volatile isn’t atomic) need to read and write a memory location []. These RMW operations are therefore misleading and should be spelled out as separate read ; modify ; write, or use volatile atomic operations which we discuss below. This was not received particularly well in the embedded community (e.g., [1]) due to said deprecation affecting compound bitwise operations on volatile variables, which are extremely widely used to interact with hardware registers. This pushback eventually resulted in C++23 un-deprecating compound bitwise operators on volatile variables [2]. [0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1152r0.html https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p11... [1]: https://www.reddit.com/r/cpp/comments/jswz3z/compound_assignment_to_volatile_must_be/ https://www.reddit.com/r/cpp/comments/jswz3z/compound_assign... [2]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2327r1.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p23...
- tialaramex 15d agoBasically on a rare occasion somebody (JF Bastien) was able to land a C++ proposal which warns you if you'd do something stupid, and inevitably C programmers cosplaying as C++ programmers insisted "it's not stupid it's advanced" and so now C++ must not even warn you this is a bad idea. It still is a bad idea, but being warned would make them feel bad.