Friday, November 24, 2006

Debugging with large integers

This is just a testimony to my ignorance; but I spent a lot of time trying to debug an OSX application that was using large unsigned integer (UInt64) values. I was trying to printf the values so I could see what they were at specific points in the application and I was always getting 0 as the result. The problem was that I was using a %d in the format specifier string which is desigated for integers; but since these were 64 bit values, that designator was unable to format them properly. Using the %lld specifier was what did the trick. In addition to requiring different format specifications for printing, 64 bit values also require different methods for performing other seemlingly simple operations. For example, to compare two unsigned 64 bit values it was necessary to use the U64Compare() function. There are various other functions for working with 64-bit integers. This was probably obvious for a lot of other folks, but it was a good lesson for me to learn.