Hi Pelle:
Compiling with Pelle's C Version 5 beta 4, the following snippet generates the following warnings
snip.c(17): warning #2154: Unreachable code.
snip.c(25): warning #2154: Unreachable code.
Thank you
Robert Wishlaw
#include <stdio.h>
#include <string.h>
static char a[6];
int main(int argc, char *argv[])
{
strcpy(a,"Hello");
while(1)
{
if(strcmp(a,"Hello")==0)
{
printf("%s\n","Hi there!");
}
break;
}
while(1)
{
if(strcmp(a,"Hello")==0)
{
printf("%s\n","Hi there again from Unreachable code land!");
}
break;
}
printf("%s\n","Hi there yet again from Unreachable code land!");
return 0; // End of main program
}
The compiler warns about an extra jump which happens to be generated for this specific case. The basic problem is to see the difference between code generated from user code, and code generated by the compiler (for higher level loops, for example).
Personally I prefer for (;;)
for an endless loop rather than while (1)
The former case generates slightly different code which happens to pass without a warning.
I will add your case as a test for the next release, but I will not do much about it for version 5.0...