Pelles C forum
Pelles C => Bug reports => Topic started 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
-
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?
-
I tried your code. Pelles C V6.50 RC #4 does not display the warning message.
-
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
-
#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.
-
#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
-
Update to rc4 and try again.