如何消除“丢弃限定词”警告? [英] How to eliminate the "discard qualifier" warning?

查看:455
本文介绍了如何消除“丢弃限定词”警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GCC和C99模式,我有一个函数声明为:

  void func(float * X); 

当我调用函数时,我使用一个易变的数组Y:

  volatile float Y [2]; 
int main()
{
func(Y);
返回0;



$ b当编译时(使用 -Wall

 警告:传递'func'的参数1会丢弃指针目标类型的限定符
blah.c:4:note:expected'float *'但参数类型为'volatile float *'

我可以用明确的(float *)类型强制转换来消除它,但是这会在代码中的许多地方重复使用。



有没有办法通过一个选项或一个附注(或类似的东西)来消除这个特定的警告?

解决方案不,你不能关掉这个警告。它告诉你你正在违反类型系统。如果您想调用 func ,您需要将指针传递给非易失性数据,或更改函数签名以接受指向易失性数据的指针。


Using GCC and C99 mode, I have a function declared as:

void func(float *X);

When I call the function, I use a volatile array Y:

volatile float Y[2];
int main()
{
    func(Y);
    return 0;
}

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 *’

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)?

解决方案

No, you can't turn that warning off. It's telling you you're violating the type system. If you want to call func you either need to pass it pointers to non-volatile data or change the function signature to accept pointers to volatile data.

这篇关于如何消除“丢弃限定词”警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆