Pelles C forum

Pelles C => FAQ => Topic started by: Grincheux on December 10, 2019, 04:27:19 PM

Title: Unreachable code
Post by: Grincheux on December 10, 2019, 04:27:19 PM
Could you make a thread on that subject.
Because I don't understand anything.
I have tested many compilers and Pelle is the only one that emits that kind of warning. I suppose it is is a good thing. But and can I correct this warning in my code.

Thank You
Title: Re: Unreachable code
Post by: frankie on December 10, 2019, 06:05:44 PM
Unreachable, or dead, code is that code that will never be executed, and for this reason will not be emitted by the compiler.
These parts are normally generated when a conditional execution resolves to a constant comparison that allows the compiler to evaluate that the code will never execute during compilation. I.e.
Code: [Select]
    const a=2;    //This is a constant value
    ...
    if (a ==10)    //This condition will never be true. The code will be removed
    {
        printf("Dead code. Will never be executed!\");
    }

Another example is when there is code after a return statement:
Code: [Select]
void foo(void)
{
    printf("foo()\n");
    return;
    printf("Dead code. Will never be executed!\");
}

The warn is very useful if you put the code there by mistake.
Title: Re: Unreachable code
Post by: Grincheux on December 10, 2019, 08:10:51 PM
Ok Frankie, I had understood this but this is not always the case.
Specially this one :

Code: [Select]
uint64_t crc64speed(uint64_t crc, const void *s, const uint64_t l)
{
/* Quickly check if CRC table is initialized to little endian correctly. */
#ifndef CRC64SPEED_DUAL
    check_init(crc64_table, LITTLE1);
#else
    check_init(crc64_table_little, LITTLE1);
#endif
    return crcspeed64little(dual ? crc64_table_little : crc64_table, crc,(void *)s, l);
}
Quote
return crcspeed64little(dual ? crc64_table_little : crc64_table, crc,(void *)s, l);

https://github.com/mattsta/crcspeed (https://github.com/mattsta/crcspeed)
https://github.com/mattsta/crc64-compare (https://github.com/mattsta/crc64-compare)
https://matt.sh/redis-crcspeed (https://matt.sh/redis-crcspeed)
Title: Re: Unreachable code
Post by: frankie on December 15, 2019, 12:12:30 AM
What is the exact warning text?
On which line? In the following line?
Code: [Select]
return crcspeed64little(dual ? crc64_table_little : crc64_table, crc,(void *)s, l);
It could also be a bug...