nice! I'm re-doing my old "integers in C" quiz and will steal this one!
-
-
-
based on a true life bug. Actual code used enum {0,1} instead of int. Years ago. Compiler didn't complain, but Lint did (with a vague "1 is outside the range". Dev suppressed it. "What do you mean a bit can't be 1? Stupid tool!"
- Još 2 druga odgovora
Novi razgovor -
-
-
I was thinking last night about how to make this melt peoples minds further. If you change to char a:1 and isOne(char i) then depending on compiler (gcc-arm/gcc-x86) you get different answers.
-
You can also prime and misdirect the reader by changing isOne to isZeroOrOne (and printing Zero, One, or Neither)
Kraj razgovora
Novi razgovor -
-
-
I think it's -1. A one bit signed integer is just a sign bit.
- Još 7 drugih odgovora
Novi razgovor -
-
-
Is it not implementation defined? Bitfields may be either big or little endian, so can “correctly” be either the sign bit or one depending on arch
-
Isn't signed overflow UB?
- Još 8 drugih odgovora
Novi razgovor -
-
-
well you did declare a signed bit-field of width 1, to store assuming 2's complement values ranging from -2^(1-1) to 2^(1-1)-1. https://taas.trust-in-soft.com/tsnippet?source=%7B%22source%22%3A%22%23include%20%3Cstdio.h%3E%5Cn%5Cnvoid%20isOne(int%20i)%20%7B%5Cn%20%20%20%20if%20(i%20%3D%3D%201)%20printf(%5C%22One%5C%5Cn%5C%22)%3B%5Cn%20%20%20%20else%20printf(%5C%22Not%20one%5C%5Cn%5C%22)%3B%5Cn%7D%5Cn%5Cnint%20main()%20%7B%5Cn%20%20%20%20struct%20%7B%20int%20a%3A1%3B%20%7Ds%3B%5Cn%20%20%20%20s.a%20%3D%201%3B%5Cn%20%20%20%20isOne(s.a)%3B%5Cn%20%20%20%20return%200%3B%5Cn%7D%5Cn%22%2C%22machdep%22%3A%22gcc_x86_64%22%2C%22entry_point%22%3A%22main%22%7D …pic.twitter.com/aulMCKDYLe
- Još 1 odgovor
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.