crc type bug


pcruce
12-01-2011, 11:52 AM
This is with respect to the crc code in chapter 22.4
icrc.h uses Uint for non-byte numeric types. nr3.h declares a Uint as a 32-bit integer(unsigned int). But Uints are passed to the inline functions lobyte & hibyte each of which are declared to take unsigned short as their argument.

I think that this is a type mismatch. 32-bit integers should not be passed to functions that take 16-bit integers.

I suggest that all of icrc.h use short ints, as it mainly works on 16-bit data types anyway. But if not, the inline functions should probably be modified to take Uints as arguments instead of short ints.

Making my case for fixing the error by switching to short ints, If 16-bit data types were used everywhere, you could make a slightly more efficient program. For example, the line: ans &= 0xffff, would no longer be necessary. And the hibyte inline function would no longer need a mask. (it could just read (Uchar) (x >> 8))

Saul Teukolsky
12-17-2011, 12:36 PM
Yes, you are correct. We will fix this in the next reprinting of the book and code release. Thanks for reporting this.

Saul Teukolsky