Blog

Math proofs and programming
Pascal Cuoq on 20 January 2012

Speaking of John Carmack, in his twitter feed, he notes: In hindsight it is surprising that I disliked doing math proofs in high school despite already being a programmer. It says a lot about the French education system that I started teaching myself programming at 6 and officially switched from...

Read More

Checking for overflows operation by operation
Pascal Cuoq on 20 January 2012

My colleague Bernard Botella pointed out an interesting example in an offline discussion following the last quiz. The setup Consider the snippet: int s; unsigned u1 u2; ... s = u1 - u2; The programmer's intention with the assignment is to compute in variable s of type int the mathematical...

Read More

A bit of explanation regarding the quiz in the last post
Pascal Cuoq on 20 January 2012

There are only positive constants in C, as per section 6.4.4 in the C99 standard: integer-constant: decimal-constant integer-suffixopt octal-constant integer-suffixopt hexadecimal-constant integer-suffixopt decimal-constant: nonzero-digit decimal-constant digit octal-constant: 0 octal-constant octal-digit hexadecimal-constant: hexadecimal-prefix hexadecimal-digit hexadecimal-constant hexadecimal-digit ... The minus sign is not part of the constant according to the grammar. The...

Read More

Constants quiz
Pascal Cuoq on 20 January 2012

What does the following program print? long long l; #include <stdio.h> int main() { l = -0x80000000; printf(\%lld" l); } $ gcc t.c && ./a.out And this one? (beware trick question) long long l; #include <stdio.h> int main() { l = -2147483648; printf("%lld" l); } $ gcc t.c && ./a.out...

Read More

Critics
Pascal Cuoq on 16 January 2012

This blog is not intended to be about computer gaming, even partially. In fact, the post I am about to link to comes from a feed I was subscribed to by accident when I changed news readers. I haven't bothered to fix this yet. The post starts with this quote:...

Read More