Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Numerical Recipes Third Edition Forum > General Problems in Using NR3

Thread Tools Rate Thread Display Modes
Old 12-01-2011, 12:52 PM
pcruce pcruce is offline
Registered User
Join Date: Nov 2011
Posts: 1
crc type bug

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))
Reply With Quote
Old 12-17-2011, 01:36 PM
Saul Teukolsky Saul Teukolsky is offline
Numerical Recipes Author
Join Date: Jan 2002
Posts: 212
Yes, you are correct. We will fix this in the next reprinting of the book and code release. Thanks for reporting this.

Saul Teukolsky
Reply With Quote

bug, check, crc, type, uint

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 09:01 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.