News for hackers. Stuff that matters.
Re:A Quiz About Integers in C by matzahboy on Sunday June 03, 2012 @06:01PM (#4061865)
I believe that the answers are incorrect. They assume that all true boolean expressions evaluate to 1, whereas the c standard only guarantees that they don't evaluate to 0.

Edit: As pointed out by the responses, I am wrong

Re:A Quiz About Integers in C by rcfox on Sunday June 03, 2012 @06:17PM (#4061899)
6.3.1.2 Boolean type

"When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1"

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf page 43

Re:A Quiz About Integers in C by jstanley on Sunday June 03, 2012 @06:43PM (#4061945)
"the c standard only guarantees that they don't evaluate to 0"

Why do people who haven't checked the C standard make such claims? My C lecturer made exactly the same mistake.

Re:A Quiz About Integers in C by cliffbean on Sunday June 03, 2012 @06:18PM (#4061901)
No, it guarantees 0 or 1; see C99 6.5.8 paragraph 6: these operators "shall yield 1 if the specified relation is true and 0 if it is false."
Re:A Quiz About Integers in C by aidenn0 on Sunday June 03, 2012 @06:16PM (#4061893)
Not true, !0 is always 1 in the C standard. Other parts are wrong though (they assume short is narrower than int, and that int is 32 bits).
Re:A Quiz About Integers in C by chc on Sunday June 03, 2012 @06:21PM (#4061907)
It's not wrong. If you read the intro, they note that those traits are implementation defined, so they say to assume you're using an implementation with those characteristics.
Re:A Quiz About Integers in C by nooop on Sunday June 03, 2012 @07:47PM (#4062067)
So this is incorrectly titled. This should be a "A Quiz About Integers in C on common x86 and x64 ABI."

Unfortunately this does not educate people to that kind of issues, which is very unfortunate.

Re:A Quiz About Integers in C by rcfox on Sunday June 03, 2012 @06:19PM (#4061902)
The assumptions are explicitly stated at the beginning of the quiz.
Re:A Quiz About Integers in C by matzahboy on Sunday June 03, 2012 @06:17PM (#4061898)
Thanks. I didn't know that