News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Possible bug with integer?

Started by bitcoin, July 22, 2019, 10:54:12 PM

Previous topic - Next topic

bitcoin

I have algo to compute CRC32. It similar to ntdll.RtlComputeCrc32 , but in Pelles it return another number. In VS all ok. Why? This is bug or feature?

So, code is

unsigned int crc32(unsigned int seed, void *msg, size_t len)
{
unsigned int crc = ~seed;

while (len--) {
crc ^= *((unsigned char *)msg)++;

for (size_t i = 0; i < 8; ++i)
crc = (crc >> 1) ^ (0xEDB88320 & ~(crc & 1) + 1);
}

return ~crc;
}


VS return 1267612143, RtlComputeCrc32 return 1267612143 , but Pelles return 3818104785

tmp = crc32(0, "abcdef", 6);

TimoVJL

#1
a fixed version ?
unsigned int crc32(unsigned int seed, void *msg, size_t len)
{
unsigned int crc = ~seed;
unsigned char *p = msg;

while (len--) {
//crc ^= *((unsigned char *)msg)++;
crc ^= *(p++);

for (size_t i = 0; i < 8; ++i)
crc = (crc >> 1) ^ (0xEDB88320 & (~(crc & 1) + 1));
}

return ~crc;
}
clang:test_crc.c(9,4): error: assignment to cast is illegal, lvalue casts are not supported
                ((unsigned char *)msg)++;
                ~^~~~~~~~~~~~~~~~~~~~~~~
May the source be with you

bitcoin

Yes, it works! I don't know C well.