So we had a discussion about C++ at work today. It seems something I've done for years and seen in a million places is UB?! uint8_t* pSomeBlob; auto pHeader = reinterpret_cast<Header*>( pSomeBlob ); This is supposedly undefined behavior, is that true?
Also, UB isn’t always a no-no. If you’re using a certain compiler and you know what that compiler will do, then it’s perfectly fine. You may one day find s compiler that doesn’t do that. UB is only bad if you don’t know your platform/compiler.
-
-
If I’m not mistaken, the reason for the wording is more for int<->float, or int<->pointer, where the types aren’t exactly related. In practice, T1*<->T2* is chill and the compiler will do what you expect.
Kiitos. Käytämme tätä aikajanasi parantamiseen. KumoaKumoa
-
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.