Given the following in C++(you might be surprised):
unsigned short x=0xFFFF;
unsigned short y=0xFFFF;
auto z=x*y;
std::cout << z;
Without checking, assuming an LP64 system what is the result:
A. 4294836225
B. -131071
C. fffe0001
D. Undefined behavior
#Cplusplus
#Cpppolls
-
-
If we used constexpr in a context that required a constant expression this would have generated a compile-time diagnostic: https://godbolt.org/z/WCi4BA Also see “Exploring undefined behavior via constexpr”:https://twitter.com/shafikyaghmour/status/1127219879457636353 …
Prikaži ovu nit -
Also see “Why must a short be converted to an int before arithmetic operations in C and C++” https://stackoverflow.com/a/24372323/1708801 …pic.twitter.com/hfcr9IBcN1
Prikaži ovu nit
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.
The answer is D, this is undefined behavior but how you might protest, unsigned number don’t have undefined behavior on overflow, do they?