Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 当变量被阴影遮挡时获取警告_C_Variables_Warnings_C99 - Fatal编程技术网

C 当变量被阴影遮挡时获取警告

C 当变量被阴影遮挡时获取警告,c,variables,warnings,c99,C,Variables,Warnings,C99,我通常希望避免这样的代码: #include <stdio.h> int main(int argc, char *argv[]){ int n = 3; for (int n = 1; n <= 10; n++){ printf("%d\n", n); } printf("%d\n", n); } #包括 int main(int argc,char*argv[]){ int n=3; 对于(int n=1;ngcc和clang都支持-Wsh

我通常希望避免这样的代码:

#include <stdio.h>

int main(int argc, char *argv[]){

  int n = 3;

  for (int n = 1; n <= 10; n++){
    printf("%d\n", n);
  }

  printf("%d\n", n);
}
#包括
int main(int argc,char*argv[]){
int n=3;

对于(int n=1;ngcc和clang都支持
-Wshadow
标志,该标志将警告相互阴影的变量。例如,我从
gcc
收到的代码警告如下:

warning: declaration of ‘n’ shadows a previous local [-Wshadow]
for (int n = 1; n <= 10; n++){
         ^
warning: shadowed declaration is here [-Wshadow]
int n = 3;
    ^
警告:声明“n”会对以前的本地[-Wshadow]造成阴影
对于(int n=1;n