News for hackers. Stuff that matters.
Re:The C++20 Naughty and Nice List for Game Devs by hotjump on Monday December 25, 2023 @10:43AM (#38763491)
I'm a junior in uni, and I hate it when I say "Yeah we learned this technique in the C class, but it's UB in C++ so please rewrite that" in reviewing friends' codes that do type-punning with unions. So I'm also very happy with the 'std::bit_cast' in general.

BTW how about std::is_constant_evaluated()? I assumed it would help folks who do heavy physics simulations, but looks like not listed in the article.

Re:The C++20 Naughty and Nice List for Game Devs by flohofwoe on Monday December 25, 2023 @11:04AM (#38763674)
TBF, I have yet to see a C++ compiler where the union type punning trick doesn't work, there would be a lot of broken code if real-world compilers would change the current behaviour no matter what the standard says.

Of course now that std::bit_cast exists it's the safe thing to do (but then there's still C code that's compiled in C++ mode which was even recommended by Microsoft because the Visual Studio team couldn't be bothered to keep their C compiler in shape until a little while ago).

Re:The C++20 Naughty and Nice List for Game Devs by gumby on Monday December 25, 2023 @11:43AM (#38763965)
> I have yet to see a C++ compiler where the union type punning trick doesn't work

The problem isn’t that compilers won’t implement the feature (that would take more work); the problem is that it’s processor-specific.

The spec doesn’t mandate many specific bit-ordering layouts (some are, such two’s complement representation being mandated which was just added, &obj == &base, I think nullptr has to be 0, etc) rather than trying to make everything a PDP-11.

Re:The C++20 Naughty and Nice List for Game Devs by anonymoushn on Monday December 25, 2023 @12:16PM (#38764282)
In these cases using bit_cast or memcpy will also "break" though :(
Re:The C++20 Naughty and Nice List for Game Devs by CamperBob2 on Monday December 25, 2023 @01:54PM (#38765048)
There would be a lot of broken code if real-world compilers would change the current behaviour no matter what the standard says

GCC maintainers: Hold my Jolt

Re:The C++20 Naughty and Nice List for Game Devs by aw1621107 on Monday December 25, 2023 @12:32PM (#38764395)
For those of us who aren't very familiar with what heavy physics simulations might involve, how would std::is_constant_evaluated() help?