warning C4146: unary minus operator
applIEd to unsigned type,result still
unsigned
码:
voID f(int n){}int main(){ unsigned int n1 = 9; f(-n1);}
但是因为函数f将它的参数作为int而不应该编译而没有任何警告?
解决方法 标准5.3.1 / 7The operand of the unary – operator
shall have arithmetic or enumeration
type and the result is the negation of
its operand. Integral promotion is
performed on integral or enumeration
operands. The negative of an unsigned
quantity is computed by subtracting
its value from 2n,where n is the
number of bits in the promoted
operand. The type of the result is the
type of the promoted operand.
关于积分促进4.5 / 1的段落
An rvalue of type char,signed char,
unsigned char,short int,or unsigned
short int can be converted to an
rvalue of type int if int can
represent all the values of the source
type; otherwise,the source rvalue can
be converted to an rvalue of type
unsigned int.
即unsigned int不会被提升为int.
总结以上是内存溢出为你收集整理的c – 对unsigned int进行一元 *** 作的编译器警告全部内容,希望文章能够帮你解决c – 对unsigned int进行一元 *** 作的编译器警告所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)