完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我有一个头文件,这个头文件要从一个或多个源文件中多次排除,如下面的例子,但是由于一些未知的原因,XC8不能编译(XC16和XC32编译成功)。这是XC8预处理器问题吗?在MPLABX v3.40、XC8 v1.38、XC16 v1.38、XC16 v1.26、XC32 v1.42Attached上测试的示例项目是示例项目。[HEADER1.H]\HEADADADER1.H\IFTEST_TEST_TEST_MACRO\TEST_TEST_TEST_TEST_MACRO\\TEST_TEST_MACRO=1.MACRO=1(TEST_MACRO=1=TEST_MACRO==1(TEST_MACRO=TEST_TEST_MACRO=1=1定义TEST_MACRO(3)#elif(TEST_MACRO==3)无符号int Var3=0;.fTEST_MACROdefine TEST_MACRO(4)endif.error“TEST_MACRO在这里没有定义。”endif[MAIN.C]include
以上来自于百度翻译 以下为原文 Hi, I have a header file which is to be included multiple times from one or more source file, like the following example, but for some unknown reason XC8 will not compile (XC16 and XC32 compile successfully). Is this a XC8 preprocessor problem? Example project tested on MPLABX v3.40, XC8 v1.38, XC16 v1.26, XC32 v1.42 Attached is the example project. [HEADER1.H] #ifdef TEST_MACRO #if (TEST_MACRO == 1) unsigned int Var1 = 0; #undef TEST_MACRO #define TEST_MACRO (2) #elif (TEST_MACRO == 2) unsigned int Var2 = 0; #undef TEST_MACRO #define TEST_MACRO (3) #elif (TEST_MACRO == 3) unsigned int Var3 = 0; #undef TEST_MACRO #define TEST_MACRO (4) #endif #else #error "TEST_MACRO is not defined here." #endif [MAIN.C] #include #define TEST_MACRO (1) #include "header1.h" #if (TEST_MACRO != 2) #error "TEST_MACRO != 2" #endif #include "header1.h" #if (TEST_MACRO == 2) #error "TEST_MACRO == 2" /* This error directive is active (expected 3 but got a 2) */ #endif #include "header1.h" #if (TEST_MACRO == 2) #error "TEST_MACRO == 2" /* This error directive is active (expected 4 but got a 2) */ #endif int main(void) { do {++Var1; ++Var2; ++Var3;} while (1); return 0; } Attachment(s) Test01.X.zip (24.36 KB) - downloaded 34 times |
|
相关推荐
6个回答
|
|
没有预处理器问题,只是纠正了错误的代码。在头文件中没有包含防护。多次包含相同的头文件需要重新考虑代码逻辑。
以上来自于百度翻译 以下为原文 no preprocessor problem, just straight up bad code. No include guards in header file Including the same header file multiple times You need to rethink your code logic. |
|
|
|
对我来说好像是个虫。在Linux上用GCC编译好。产生这种情况:
以上来自于百度翻译 以下为原文 Looks like a bug to me. Compiles fine with GCC on Linux. Produces this: # 1 "main.c" # 1 " # 1 " # 1 "main.c" # 1 "header1.h" 1 unsigned int Var1 = 0; # 4 "main.c" 2 # 1 "header1.h" 1 # 12 "header1.h" unsigned int Var2 = 0; # 9 "main.c" 2 # 1 "header1.h" 1 # 19 "header1.h" unsigned int Var3 = 0; # 14 "main.c" 2 int main(void) { do {++Var1; ++Var2; ++Var3;} while (1); return 0; } |
|
|
|
GCC与兼容代码的标准相去甚远。XC16和XC32是GCC。这可能是OCG的一个问题。XC8不单独编译文件并在最后进行链接。问题是它需要由C Standard.edit单独工作:绝望(至少我希望不是)
以上来自于百度翻译 以下为原文 GCC is far from the standard for compliant code. XC16 and XC32 are GCC. It could be an issue with OCG. XC8 does not compile files separately and link then at the end. The Question is it required to work by the C Standard. edit: separately not desperately (at least I hope not) |
|
|
|
我是编译文件“DePury”的那个人。我认为尼尔的意思是“分开的”。我认为可怕的头文件只是试图测试一些嵌套的头文件如何工作的模糊的细节,它不是真实世界的例子。它也犯了在头文件中分配变量值的根本罪过。
以上来自于百度翻译 以下为原文 I'm the one that compiles files "deperately". I think Neil meant "seperately". I assume that awful looking header file is just trying to test some obscure details about how nested header files work, it's not a real world example. It also commits the cardinal sin of assigning variable values within a header file. |
|
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1929 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3175 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2227 浏览 5 评论
736浏览 1评论
619浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
507浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
633浏览 0评论
530浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 04:17 , Processed in 1.212124 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号