完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,AllI一直在做一个项目来创建一些旧的CCS代码到XC8的简化转换过程,并使用宏实现了几乎相同的代码,但是我想我已经发现了一个IDE错误,使用内联IF语句:{条件}?{true}:{false };从我所看到的,我相信真正的条件是抛出一个错误的无代码错误,下面的例子将帮助其他人重现同样的错误:1)要编译的宏:WReg=0:WReg=1;这是宏发现故障的简单示例,结果在不同的输入条件下,如果存在编译问题,则移动(模式)=0?与IF相同的行并删除结束,这被编辑在这里更容易阅读。2)真条件主“C”文件宏:Test-InLIF(0);2.1)编译程序集:82:Test-InLIVIF(0);07D7 0020 MOVLB 0x00 7D8 0189 CLRF WReGeTe完全符合预期。2.2)编译器警告:CCSYTest.C:82:警告:(759)表达式不生成代码,这是错误的错误消息警告,代码已正确生成。3)错误条件“C”文件宏:Test-InLIF(1);3.1)编译程序集:82:Test-In LILIF(1);07D6 3001 MOVLW 0x107D7 0020 MOVLB 0x00 7D8 0089 MOVWF WRGETEX是EX。编译器警告:完全没有警告,这是正确的。这不是一个编译器中断的问题,更麻烦的预编译器类型错误检测,我相信这对于IF {},否则{},Endif语句也是正确的。对于这个问题的任何反馈或未来计划修复都将是GRAA。虽然我不是一个很长时间的C程序员,但是我的汇编程序年能追溯到很多这样的烦心事,所以我希望我可以使用ASM StiLL。
以上来自于百度翻译 以下为原文 Hi All I have been working on a project to create a simplified conversion process for some old CCS code to XC8 and by using Macro's have achieved near identical code, however I think I have found an IDE fault using the inline IF statement: {condition}?{true}:{false}; From what I am seeing I believe the true condition is throwing a false no code error, the following examples will help anyone else reproduce the same fault: 1) The macro to be compiled: #define test_inlineIF(mode) (mode)==0? WREG=0: WREG=1; This is a simple example of the macro found to fault, the results are below with the different input conditions, if there is an issue with compiling, move the (mode)==0? to the same line as the IF and remove the end , this was edited to be easier to read on here. 2) True condition Main 'C' file macro: test_inlineIF( 0 ); 2.1) Compiled assembly: 82: test_inlineIF( 0 ); 07D7 0020 MOVLB 0x0 07D8 0189 CLRF WREG This is exactly as expect. 2.2) Compiler Warning: CCS_Test.c:82: warning: (759) expression generates no code This I believe is the false error message warning, code has been produced correctly. 3) False condition Main 'C' file macro: test_inlineIF( 1 ); 3.1) Compiled assembly: 82: test_inlineIF( 1 ); 07D6 3001 MOVLW 0x1 07D7 0020 MOVLB 0x0 07D8 0089 MOVWF WREG This is exactly as expect. 3.2) Compiler Warning: No warnings at all, which is correct. This is not a compiler breaking issue, more of an annoying pre-compiler type error detection, I believe this is also true for the IF{}, ELSE{}, ENDIF statements. Any feedback or future planned fix for this issue would be great to hear about, although I am not a long time 'C' programmer, my assembler years date back many and annoyances like this make me wish I could use ASM still. Si. |
|
相关推荐
7个回答
|
|
因为条件总是正确的,所以您得到警告消息以指示没有为WReg=1生成代码。
以上来自于百度翻译 以下为原文 As the condition is always true, you get the warning message to indicate no code was generated for WREG=1. |
|
|
|
OP表示编译器在条件总是为真时生成警告(其中“否则”子句不生成代码),并且当条件总是为false时,它会生成{NO}警告(其中“THE”子句不生成代码)。它与警告不一致,也就是说,XC8是一个C编译器,而不是IDE。这不是一个内联IF.()语句。这个?是条件算子A.k. A三元运算符.这个运算符被用作If()语句的快捷方式。
以上来自于百度翻译 以下为原文 OP is saying the compiler generates a warning when the condition is always true (where the "else" clause generated no code) and it generates _no_ warning when the condition is always false (where the "then" clause generated no code). It is not consistent with the warning. That said, XC8 is a C compiler, not an IDE. That is not an inline if() statement. The ?: is the conditional operator a.k.a the ternary operator. This operator is used as a shortcut for the if() statement. |
|
|
|
谢谢你1和0,这是问题的经验,总体上是一个小烦恼,但应该纠正。总的来说,转换过程现在可以采取一个CCS项目,并按照每一步将其转换为XC8项目,宏替代取代旧的CCS命令。这产生了在ROM和RAM需求中几乎相同大小的固件,而不需要完整的重写,并且允许进一步开发,其他项目使用尚未写入的替换宏。
以上来自于百度翻译 以下为原文 Thank you 1and0, that is the problem being experienced, overall its a minor annoyance but one which should be corrected. Overall the conversion process is now able to take a CCS project and by following each step convert it to a XC8 project where macro substitution replaces the old CCS commands. This has produced a firmware of near identical size in ROM and RAM requirements without needing a complete rewrite and allows for further development where other projects use as yet unwritten replacement macros. |
|
|
|
设置WREG是一个坏主意在C,它只有一个寄存器工作。应该有编译器警告。它看起来应该是这样的:模式=x==100?50:20
以上来自于百度翻译 以下为原文 #define test_inlineIF(mode) (mode)==0? WREG=0: WREG=1 Setting wreg is a bad idea in C, it only has one register to work with. There should be compiler warnings. It should look something like this: mode = x == 100 ? 50 : 20 |
|
|
|
HyGoT2015感谢您的反馈,所提供的示例只是一个例子,使用WRGG= X是一个哑命令来突出这个问题,不重要的是什么代码,对于提出的问题也是如此。我必须用最简单的方法来解释这个问题和到期。20年的纯汇编程序编程,使用了我所知道的工作。唉,我不能把整个互联网放在NDA下,所以不能发布我开发的任何实际代码,请理解,即使我在现实生活中也不会使用这样的方法。
以上来自于百度翻译 以下为原文 Hi Gort2015 Thank you for your feedback, the example provided was just that, an example, using the WREG=x was a dummy command to highlight the issue, it does not matter what code is there, the same is true for the issue presented. I had to use the simplest method possible to explain the issue and due to 20 years of pure assembler programming, used what I knew would work. Alas I can not put the whole of the internet under an NDA so could not release any actual code which I have developed, please understand even I would never use such a method in real life. Si. |
|
|
|
忽略WREG寄存器。它不是内联的,只是宏替换代码。它仍然会被编译成代码。请单击其出现的宏。选择导航,然后选择查看宏扩展。如果不是,我不会使用三进制。在宏中,它看起来很混乱。7:11In x=5,y;y=Test-In LILIF(x,13);展开:y= x=13:7?11;
以上来自于百度翻译 以下为原文 Ignoring the wreg register. It's not inline, just a macro replacing code. It will still be compiled as code. Write click the macro where it appears. Select Navigation then select View macro expansion. I would not use the ternary if then, "?:" in macros, it just looks confusing. #define test _inlineIF(mode, is) mode == is ? 7 : 11 int x = 5, y; y = test_inlineIF(x, 13); Expansion: y = x == 13 : 7 ? 11; |
|
|
|
通常使用的括号。7:11)int x=5,y;y=TestIn INLINIF(x,13)+ 17;展开:y=(x==13:7)。11)+ 17;
以上来自于百度翻译 以下为原文 With parenthesis that is normally used. #define test _inlineIF(mode, is) (mode == is ? 7 : 11) int x = 5, y; y = test_inlineIF(x, 13) + 17; Expansion: y = (x == 13 : 7 ? 11) + 17; |
|
|
|
只有小组成员才能发言,加入小组>>
5136 浏览 9 评论
1987 浏览 8 评论
1917 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3155 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2215 浏览 5 评论
702浏览 1评论
593浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
476浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
608浏览 0评论
503浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-5 21:28 , Processed in 1.394296 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号