I have the following test code, file test.c:
#include <stdio.h>
int *func()
{
int i = 123;
return &i;
}
int main()
{
printf("%d\n", *func());
}
If I use the command to compile it that is OK,
gcc test.c -o test
It will have the following warning information:
warning: address of stack memory associated with local variable 'i'
returned [-Wreturn-stack-address]
return &i;
^
1 warning generated.
But it can output the result: 123
If I use the command:
gcc -Werror test.c -o test
It will have the following error information:
error: address of stack memory associated with local variable 'i'
returned [-Werror,-Wreturn-stack-address]
return &i;
^
1 error generated.
Now I want to use the -Werror option, but I also want to ignore the address of stack memory associated with local variable 'i' warning. What should I do?