I realized that I need compiler flag -Wshadow
after I mess up some code, so I decide to use it in Codeblocks
too, but it doesn't work and I can't figure out why.
The following code:
#include <stdio.h>
int main(void){
int i = 0;
int arr[] = {1,2,3};
for (int i=0 ; i < 3 ; i++){
printf("%d ",arr[i]);
}
printf("\nI = %d\n",i);
}
If I try to compile it in my Terminal
with the following flags
:
-Wall -Wextra -Werror -Wstrict-prototypes -Wconversion -Wmissing-prototypes -Wold-style-definition -Wshadow -O0 -g
I get the following Output, which is OK:
program.c: In function ‘main’:
program.c:7:14: error: declaration of ‘i’ shadows a previous local [-Werror=shadow]
for (int i=0 ; i < 3 ; i++){
^
program.c:4:9: note: shadowed declaration is here
int i = 0;
^
cc1: all warnings being treated as errors
Now using the same Compiler Flags
doesn't seems to work, compiles fine with no warnings, just like the flag -Wshadow
is not present.
Does anyone know how to fix this?
GCC version is:
gcc (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204
When you add compiler flags via the IDE, it doesn't automatically mark any existing object files or executable as out-of-date.
You need to click on "Rebuild" to do a full rebuild of your code using the new flags.