Skip to main content

I would modify the previous answer by replacing the last three lines with:

#define crc4( x) crcByte(x), crcByte(x+1), crcByte(x+2), crcByte(x+3)
#define crc16( x) crc4(x), crc4(x+4), crc4(x+8), crc4(x+12)
#define crc64( x) crc16(x), crc16(x+16), crc16(x+32), crc16(x+48)
#define crc256( x) crc64(x), crc64(x+64), crc64(x+128), crc64(x+192)

#define crc4( x)    crcByte(x), crcByte(x+1), crcByte(x+2), crcByte(x+3)
#define crc16( x)   crc4(x), crc4(x+4), crc4(x+8), crc4(x+12)
#define crc64( x)   crc16(x), crc16(x+16), crc16(x+32), crc16(x+48)
#define crc256( x)  crc64(x), crc64(x+64), crc64(x+128), crc64(x+192)

Where crcByte is his K macro without the trailing comma. Then build the table itself with:

static const unsigned long crc32Table[256] = { crc256( 0)};

static const unsigned long crc32Table[256] = { crc256( 0)};

And never leave out the size of the array as the compiler will then verify that you have the correct amount of elements.

I would modify the previous answer by replacing the last three lines with:

#define crc4( x) crcByte(x), crcByte(x+1), crcByte(x+2), crcByte(x+3)
#define crc16( x) crc4(x), crc4(x+4), crc4(x+8), crc4(x+12)
#define crc64( x) crc16(x), crc16(x+16), crc16(x+32), crc16(x+48)
#define crc256( x) crc64(x), crc64(x+64), crc64(x+128), crc64(x+192)

Where crcByte is his K macro without the trailing comma. Then build the table itself with:

static const unsigned long crc32Table[256] = { crc256( 0)};

And never leave out the size of the array as the compiler will then verify that you have the correct amount of elements.

I would modify the previous answer by replacing the last three lines with:

#define crc4( x)    crcByte(x), crcByte(x+1), crcByte(x+2), crcByte(x+3)
#define crc16( x)   crc4(x), crc4(x+4), crc4(x+8), crc4(x+12)
#define crc64( x)   crc16(x), crc16(x+16), crc16(x+32), crc16(x+48)
#define crc256( x)  crc64(x), crc64(x+64), crc64(x+128), crc64(x+192)

Where crcByte is his K macro without the trailing comma. Then build the table itself with:

static const unsigned long crc32Table[256] = { crc256( 0)};

And never leave out the size of the array as the compiler will then verify that you have the correct amount of elements.

Source Link
Jay
  • 31
  • 1

I would modify the previous answer by replacing the last three lines with:

#define crc4( x) crcByte(x), crcByte(x+1), crcByte(x+2), crcByte(x+3)
#define crc16( x) crc4(x), crc4(x+4), crc4(x+8), crc4(x+12)
#define crc64( x) crc16(x), crc16(x+16), crc16(x+32), crc16(x+48)
#define crc256( x) crc64(x), crc64(x+64), crc64(x+128), crc64(x+192)

Where crcByte is his K macro without the trailing comma. Then build the table itself with:

static const unsigned long crc32Table[256] = { crc256( 0)};

And never leave out the size of the array as the compiler will then verify that you have the correct amount of elements.