NO

Author Topic: Unreachable code  (Read 379 times)

Offline Grincheux

  • Member
  • *
  • Posts: 36
  • Never be pleased, always improve
    • Arachne
Unreachable code
« 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
-------------------------
Kenavo

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1746
Re: Unreachable code
« Reply #1 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.
« Last Edit: December 10, 2019, 06:08:25 pm by frankie »

Offline Grincheux

  • Member
  • *
  • Posts: 36
  • Never be pleased, always improve
    • Arachne
Re: Unreachable code
« Reply #2 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/crc64-compare
https://matt.sh/redis-crcspeed
« Last Edit: December 10, 2019, 08:12:38 pm by Grincheux »
-------------------------
Kenavo

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1746
Re: Unreachable code
« Reply #3 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...