Pelles C forum

Pelles C => Bug reports => Topic started by: MaurizioF on May 18, 2011, 03:29:21 PM

Title: Extra" unreachable code" warning
Post by: MaurizioF on May 18, 2011, 03:29:21 PM
The following example generates an extra warning :
warning #2154: Unreachable code.

Tested with version 6.00.4

Regards.
Maurizio.

#include <stdio.h>
int main(int argc, char *argv[])
{
  if (argc==1)
    return 1;
  else
    return 0;
}   //  here the warning is signalled
Title: Re: Extra" unreachable code" warning
Post by: CommonTater on May 18, 2011, 07:29:30 PM
A minor C foible that may or may not be your problem... 

Every file in C requires at least 1 blank line at the end.  I've had it pop up a couple of different warnings (not errors) and most often when I just can't explain it any other way, I'll go to the bottom of the source page, hit enter a couple of times and the problem goes away.  (FWIW, this doesn't appear to be Pelles C specific, Watcom and Tiny do it too.)

This may or may not be your problem... but what's it going to hurt to try it?



Title: Re: Extra" unreachable code" warning
Post by: Vortex on May 18, 2011, 11:39:12 PM
I tried your code. Pelles C V6.50 RC #4 does not display the warning message.
Title: Re: Extra" unreachable code" warning
Post by: TimoVJL on May 19, 2011, 05:25:55 AM
v6.00: Only when optimizations are on.

EDIT:
Code: [Select]
#include <stdio.h>
int main(int argc, char *argv[])
_main:
  [00401000] 8B442404               mov             eax,dword ptr [esp+4]
{
  if (argc==1)
  [00401004] 83F801                 cmp             eax,+1
  [00401007] 0F94D1                 sete            cl
  [0040100A] 0FB6C1                 movzx           eax,cl
  [0040100D] C3                     ret             
    return 1;
  else
    return 0;
}   //  here the warning is signalled
  [0040100E] C3                     ret             
Title: Re: Extra" unreachable code" warning
Post by: AlexN on May 19, 2011, 11:21:05 AM
#include <stdio.h>
int main(int argc, char *argv[])
{
  if (argc==1)
    return 1;
  else
    return 0;
}   //  here the warning is signalled
Where is the problem, I think the warning is correct. The compiler generates code for the end of the function and this code will be never reached, because there are return in both cases of your if.
Title: Re: Extra" unreachable code" warning
Post by: CommonTater on May 19, 2011, 04:30:53 PM
#include <stdio.h>
int main(int argc, char *argv[])
{
  if (argc==1)
    return 1;
  else
    return 0;
}   //  here the warning is signalled
Where is the problem, I think the warning is correct. The compiler generates code for the end of the function and this code will be never reached, because there are return in both cases of your if.

That's easy to test for... just comment out the else statement.

Code: [Select]
#include <stdio.h>
int main(int argc, char *argv[])
{
  if (argc==1)
    return 1;
//  else
    return 0;
}   //  here the warning is signalled
Title: Re: Extra" unreachable code" warning
Post by: MichaelT on May 20, 2011, 02:00:46 PM
Update to rc4 and try again.