Stupid question from the rookie, but if you take your "bad example" and cast everything to uint32 instead of uint8? Btw, you can use uint8_t directly, without using cstdint nor std::uint8_t.
-
-
-
That works fine!
Kraj razgovora
Novi razgovor -
-
-
Hi
@PaulDreik , I would be interested to understand what you write, as it is a bit technical. As understanding such UB allows to go deeper in C++ Can you explain to me what is the challenge ? Thank you#cpp#cplusplus -
Please see the wonderful cppinsights tool, that shows the casts: https://cppinsights.io/s/b544729f
@shafikyaghmour gave excellent links to read up on the details in his reply! - Još 1 odgovor
Novi razgovor -
-
-
Note your godbolt does not produce the diagnostic you indicate. Also note that shifting into the sign bit is not undefined behavior see DR 1457, this was change right after C++11. http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1457 … This is subject of one of my fav Howard quotes: https://stackoverflow.com/questions/19593938/is-left-shifting-a-negative-integer-undefined-behavior-in-c11#comment29091986_19593938 …pic.twitter.com/48pVaMhTMT
-
Outside of that don't invoke undefined behavior if you are. Except in rare circumstances(your implementing std::vector) it can done w/o UB. If the compilers don't exploit it now they may in the future.
- Još 2 druga odgovora
Novi razgovor -
-
-
The GCC manual promises that GCC does not exploit this for C: https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Integers-implementation.html#Integers-implementation … I'm pretty sure the same is true for C++ too.
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
Maybe that sounds stupid question but what is the meaning of writting : (uint8)(p)[0] with p unsigned char* ? [0] is applied to p ? or to (uint8)(p) ?
-
I would have said to p , because I don't see the meaning of applying it to something of type uint8.
Kraj razgovora
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.