我正在寻找解释为什么要给我gcc这个警告。
我正在使用带有标志的gcc-3on进行编译,gcc 对我说这个警告:cygwin-Wunreachable-code
main.c:223:警告:永远不会被执行
就是这一行:while(fgets(line, MAX_LINE, stdin) != NULL) {
此代码位于根据命令行参数(由 解析)动态设置的if(exp) { }块内,请查看代码部分:expgetopt()
 if(mystruct.hastab) {
默认值为0. 但是1如果将-t标志传递给应用程序,它就变成了,如下所示:
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 {
       //...
      }
    }
因此,执行代码是有原因的。碰巧。