ysa*_*sap 5 c gcc c99 suppress-warnings
使用 GCC 和 C99 模式,我有一个函数声明为:
void func(float *X);
Run Code Online (Sandbox Code Playgroud)
当我调用该函数时,我使用了一个可变数组 Y:
volatile float Y[2];
int main()
{
func(Y);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
When compiling (with -Wall
), I get the following warning:
warning: passing argument 1 of ‘func’ discards qualifiers from pointer target type
blah.c:4: note: expected ‘float *’ but argument is of type ‘volatile float *’
Run Code Online (Sandbox Code Playgroud)
I can eliminate it with an explicit (float *)
type cast, but this repeats in many places in the code.
Is there a way to eliminate this specific warning, with an option or a pragma (or something equivalent)?
不,您无法关闭该警告。它告诉你你违反了类型系统。如果您想调用,func
则需要向其传递指向非易失性数据的指针,或者更改函数签名以接受指向易失性数据的指针。