I'm looking for an explanation why gcc
are giving this warning for me.
I'm compiling with the gcc-3
on cygwin
with the -Wunreachable-code
flag, and the gcc says this warning for me:
main.c:223: warning: will never be executed
That's this line: while(fgets(line, MAX_LINE, stdin) != NULL) {
This code is inside a if(exp) { }
block where exp
is dynamically set according to command-line-arguments(parsed by getopt()
), look at the code part:
if(mystruct.hastab) {
the default value is 0
. But it's become 1
if -t
flag is passed to application, as you can see at following:
struct mystruct_t {
//...
int hastab;
} mystruct;
int main(int argc, char *argv[])
{
int opt;
memset(&mystruct, 0, sizeof(mystruct));
while((opt = getopt(argc, argv, optString)) != -1) {
switch(opt) {
case 't':
mystruct.hastab = 1;
break;
//....
}
}
proc();
return 0;
}
void
proc(void)
{
char *buf, *tmpbuf, line[MAX_LINE + 1], *p, *fullfilename;
if(mystruct.hastab) {
while(fgets(line, MAX_LINE, stdin) != NULL) {
//...
}
} else {
//...
}
}
So, there's a reason for the code be executed. As happens.