NO

Author Topic: Invalid warnings?  (Read 2652 times)

Offline Robert

  • Member
  • *
  • Posts: 245
Invalid warnings?
« on: May 24, 2008, 06:32:43 AM »
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

Code: [Select]
#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
}


Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Invalid warnings?
« Reply #1 on: May 24, 2008, 06:43:23 PM »
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
Code: [Select]
for (;;) for an endless loop rather than
Code: [Select]
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...
/Pelle