这个警告是什么意思,我该如何摆脱它? [英] What is the meaning of this warning, and how do I get rid of it?
问题描述
我在以下
行中有一部分代码:
volatile unsigned char x;
unsigned int f (unsigned char * y);
当我这样做时
unsigned int z = f(& x);
编译器发出以下警告:
警告:传递`f'的arg 1'从指针目标类型中丢弃限定符
这究竟是什么意思?如何更改我的代码以便
编译器对此感到满意?
I have a portion of code along the following
lines:
volatile unsigned char x ;
unsigned int f(unsigned char *y) ;
When I do
unsigned int z = f(&x) ;
the compiler issues the following warning:
warning: passing arg 1 of `f'' discards qualifiers from pointer target type
What does this exactly mean? How do I change my code so that the
compiler is happy about it?
推荐答案
James H. Newman写道:
James H. Newman wrote:
我有以下代码的一部分
行:
volatile unsigned char x;
unsigned int f(unsigned char * y);
当我这样做时
unsigned int z = f(& x);
编译器发出以下警告:
警告:传递f丢弃的arg 1指针目标类型的限定符
这究竟是什么意思?
I have a portion of code along the following
lines:
volatile unsigned char x ;
unsigned int f(unsigned char *y) ;
When I do
unsigned int z = f(&x) ;
the compiler issues the following warning:
warning: passing arg 1 of `f'' discards qualifiers from pointer target type
What does this exactly mean?
这意味着你要丢弃易变信号。限定符。
如何更改我的代码,以便
It means you''re discarding the "volatile" qualifier.
How do I change my code so that the
编译器对此感到满意?
compiler is happy about it?
不要使用volatile?
-
Mark McIntyre >
CLC FAQ< http://c-faq.com/>
CLC自述文件:< http://www.ungerhu.com/jxh/ clc.welcome.txt>
don''t use volatile?
--
Mark McIntyre
CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
在文章< g5 ********** @ registered.motzarella.org>,
James H. Newman< Ne ****** @ exicite.comwrote:
In article <g5**********@registered.motzarella.org>,
James H. Newman <Ne******@exicite.comwrote:
我在以下
行中有一部分代码:
I have a portion of code along the following
lines:
volatile unsigned char x;
unsigned int f(unsigned char * y);
volatile unsigned char x ;
unsigned int f(unsigned char *y) ;
>当我做
>When I do
unsigned int z = f (& x);
unsigned int z = f(&x) ;
>编译器发出以下警告:
>the compiler issues the following warning:
> ;警告:传递`f'的arg 1'从指针目标类型中丢弃限定符
>warning: passing arg 1 of `f'' discards qualifiers from pointer target type
这究竟是什么意思?
What does this exactly mean?
x是易失性的,因此& x是指向volatile变量的指针。但是,
接收函数的原型是非易失性的,因此不会为了保持易失性语义而知道。
x is volatile, so &x is a pointer to a volatile variable. However,
the receiving function is prototyped for non-volatile and so is not
going to know to preserve volatile semantics.
如何更改我的代码以便
编译器对此感到满意?
How do I change my code so that the
compiler is happy about it?
你可以用y表示原型f,因为它是易变的。或者您可以创建一个新的非易失性变量,用x'的当前值初始化,
将其发送到f并将修改后的结果存储到f之后。但是,如果x碰巧是内存映射的I / O寄存器之类的话,那么
,或者发生由信号处理例程设置的
,然后可能赢了'$
给你你想要的结果。
-
当前的垃圾邮件:每天750-800封邮件(3月4日, 2008)
You could prototype f with y being volatile. Or you could create a
new non-volatile variable, initialize that with x''s current value,
send that to f and store the modified result after f into x. However,
if x happens to be a memory-mapped I/O register or the like, or happens
to be set by a signal processing routine, then that probably won''t
give you are result you want.
--
Current spam load: 750-800 messages per day (March 4, 2008)
James H. Newman写道:
James H. Newman wrote:
我有以下代码的一部分
行:
volatile unsigned char x;
unsigned int f(unsigned char * y);
>
当我这样做时
unsigned int z = f(& x);
编译器发出以下警告:
警告:从指针目标传递arg 1'f''丢弃限定符
类型
I have a portion of code along the following
lines:
volatile unsigned char x ;
unsigned int f(unsigned char *y) ;
When I do
unsigned int z = f(&x) ;
the compiler issues the following warning:
warning: passing arg 1 of `f'' discards qualifiers from pointer target
type
这意味着它所说的。由于''f''原型为取无符号
char *,因此'x''的挥发性限定符在被传递时被丢弃
到''f ''。另请注意,表达式& x实际上是volatile类型
unsigned char ** - 而不是您希望传递给''f'的类型。
It means what it says. Since ''f'' is prototyped as taking an unsigned
char *, the volatile qualifier of ''x'' is discarded when it is passed
to ''f''. Also note that the expression &x is actually of type volatile
unsigned char ** - not the type that you want to be passing to ''f''.
这究竟是什么意思?如何更改我的代码以便编译器对它感到高兴?
?
What does this exactly mean? How do I change my code so that
the compiler is happy about it?
原型并将''''定义为:
unsigned int f(volatile unsigned char * y){/ * ... * /}
如果''f''需要更改调用者'的论点副本那么你
可能需要:
unsigned int f(volatile unsigned char **){/ * ... * /}
Prototype and define ''f'' as:
unsigned int f(volatile unsigned char *y) { /* ... */ }
If ''f'' needs to change the caller''s copy of it''s argument then you
probably want:
unsigned int f(volatile unsigned char **y) { /* ... */ }
>
这篇关于这个警告是什么意思,我该如何摆脱它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!