From: C. M. <cm...@gm...> - 2010-04-03 01:42:49
|
This question must come up all the time, but I'm not picking the right keywords for searching the archives... I just grabbed pycrc-0.7.5 and generated C99 code for CRC16 with the default polynomial. My platform is Visual Studio (various versions) and I am using Alexander Chemeris's implementation of stdint.h, which I think is probably fine. All three generated functions crc_init(), crc_table_gen(), and crc_finalize() implicitly cast the return value of crc_reflect() [which returns unsigned_long] to crc_t. The latter is uint16_t which is an unsigned short (per Chemeris's stdint.h). So naturally, the compiler warns about possible loss of data. It's clear enough to me that we want the final crc value to be 16 bits. But do we really mean to discard the upper-half of crc_reflect? And if so, why is there not an explicit cast? If that answer is efficiency, fine. But I'm afraid I do not understand the CRC algorithm well enough to be sure. Thanks! |