完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
您好,我很少关注隐式签名到无符号转换警告。为什么所有的变量都被声明为无符号,我仍然得到这个警告?上面例子中的值是否被视为无符号或有符号字符?在这种情况下,变量“C”的值是150还是其他?同样,在下一个示例中,变量在下面的表达式中实际如何处理?如果变量“b2”可能被当作符号char而不是未签名,结果会大不相同,因此我需要理解这一点。
以上来自于百度翻译 以下为原文 Hello I have few concerns on implicit signed to unsigned conversion warning. Why do I keep getting this warning even though all the variables are declared as unsigned? unsigned char a = 70; unsigned char b = 2; unsigned char c = 10; c += a * b; // warning: (373) implicit signed to unsigned conversion Does the value in the example above will be treated as unsigned or signed char? In this case will the value of variable "c" be 150 or something else? Similarly in the next example, how are the variables actually treated in the expression below? If the variable "b2" might get treated as signed char instead of unsigned, the outcome would be much different hence I need to understand this. unsigned char a2 = 0; unsigned char b2 = 202; unsigned char c2 = 203; unsigned char d2 = 204; unsigned char e2; e2 = a2 < b2 ? c2 : d2; //warning: (373) implicit signed to unsigned conversion |
|
相关推荐
8个回答
|
|
|
*& lt;& gt;运算符将它们的操作数转换为已签名的int。=运算符将结果转换为无符号char。警告是有效的,但对于您所显示的代码,没有任何值得关注的内容。
以上来自于百度翻译 以下为原文 The * < > operators convert their operands to a signed int. The = operator will convert the result back to unsigned char. The warning is valid, but not anything to be concerned about with the code you've shown. |
|
|
|
|
|
对于每一行给UCHAR变量分配一个常数,难道你没有得到警告吗?我想,因为常量没有后缀“u”,而且我看不出有理由得到“E2=…”行的警告。
以上来自于百度翻译 以下为原文 Don't you get a warning for each line assigning a const to the uchar variables ? I'd expect that as the constants are not suffixed 'u'. And I can't see a reason to get the warning for the 'e2 = ...' line. |
|
|
|
|
|
因为L&T和& GT操作符像上面提到的那样提升它们的操作数。
以上来自于百度翻译 以下为原文 Because the < and > operators promote their operands as I mentioned above. |
|
|
|
|
|
OOP-仍然学习。无论如何,直接和不分配的结果-只是评估来决定应用哪个任务。在这种情况下,人们可能会认为警告“过度设计”。
以上来自于百度翻译 以下为原文 Oops - still learning. Anyway, the direct result of < is nor assigned - just evaluated to decide which assignment to apply. In this case one might consider the warning "overengineered". |
|
|
|
|
|
我也惊讶于这个ONEE2= A2&lt;B2?C2:D2;//警告:(373)隐式签名到无符号转换,如果将其更改为E2=(A2和l2;B2),则如何?C2:D2;
以上来自于百度翻译 以下为原文 I'm also surprised about this one e2 = a2 < b2 ? c2 : d2; //warning: (373) implicit signed to unsigned conversion What if you change it to e2 = (a2 < b2) ? c2 : d2; |
|
|
|
|
|
实际上,我认为这是一个事实,条件运算符推广第二个和第三个参数是什么引起了警告,而不是l& lt;& gt;运算符。
以上来自于百度翻译 以下为原文 Actually, I think it's the fact that the conditional operator promotes its second and third arguments is what is causing the warning, not the < > operators. |
|
|
|
|
|
老实说-关于什么……………)表示促进其他选择是不合理的。不管怎么说,看来我们得忍受这一段时间了。
以上来自于百度翻译 以下为原文 Honestly - regarding what the (... ? ... : ...) stands for a promotion of the alternatives is not reasonable. Anyway, seems we'll have to live with this for a while. |
|
|
|
|
|
对于三元运算符,第二和第三操作数被提升,好像它们是相同表达式的操作数。也就是说,无符号字符的两个操作数都被提升为已签名的int。运算符是第二个操作数和第三个操作数的结果,因此,已签名的int的结果被转换并存储在一个无符号字符中。
以上来自于百度翻译 以下为原文 For the ternary operator, the 2nd and 3rd operands are promoted as if they were operands of the same expression. That is, both operands of unsigned char are promoted to signed int. The return type of the ?: operator is that of the 2nd and 3rd operands, so the result of signed int is converted and stored in an unsigned char. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
514 浏览 0 评论
5819 浏览 9 评论
2351 浏览 8 评论
2238 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3546 浏览 3 评论
1170浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1124浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
893浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
514浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-18 07:25 , Processed in 1.070060 second(s), Total 88, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1745