NO

Author Topic: Extra" unreachable code" warning  (Read 4550 times)

MaurizioF

  • Guest
Extra" unreachable code" warning
« 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

CommonTater

  • Guest
Re: Extra" unreachable code" warning
« Reply #1 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?




Offline Vortex

  • Member
  • *
  • Posts: 858
    • http://www.vortex.masmcode.com
Re: Extra" unreachable code" warning
« Reply #2 on: May 18, 2011, 11:39:12 PM »
I tried your code. Pelles C V6.50 RC #4 does not display the warning message.
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2107
Re: Extra" unreachable code" warning
« Reply #3 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             
« Last Edit: May 19, 2011, 05:11:19 PM by timovjl »
May the source be with you

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Extra" unreachable code" warning
« Reply #4 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.
best regards
 Alex ;)

CommonTater

  • Guest
Re: Extra" unreachable code" warning
« Reply #5 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
« Last Edit: May 19, 2011, 04:32:30 PM by CommonTater »

MichaelT

  • Guest
Re: Extra" unreachable code" warning
« Reply #6 on: May 20, 2011, 02:00:46 PM »
Update to rc4 and try again.