Extra" unreachable code" warning

Started by MaurizioF, May 18, 2011, 03:29:21 PM

Previous topic - Next topic

MaurizioF

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

CommonTater

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?




Vortex

I tried your code. Pelles C V6.50 RC #4 does not display the warning message.
Code it... That's all...

TimoVJL

#3
v6.00: Only when optimizations are on.

EDIT:
#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             
May the source be with you

AlexN

Quote from: MaurizioF on May 18, 2011, 03:29:21 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.
best regards
Alex ;)

CommonTater

#5
Quote from: AlexN on May 19, 2011, 11:21:05 AM
Quote from: MaurizioF on May 18, 2011, 03:29:21 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.


#include <stdio.h>
int main(int argc, char *argv[])
{
  if (argc==1)
    return 1;
//  else
    return 0;
}   //  here the warning is signalled


MichaelT