Eclipse CDT syntax error on __attribute__ keyword

醉酒当歌 提交于 2019-12-21 23:56:34

问题


I would like to know if there is a way to get rid of CDT syntax error warnings when using gcc's "__attribute__" keyword.

It goes without saying that I would not like to switch off CDT syntax check.


回答1:


The "ECLIPSE_THINKS_THIS_IS_SET_BUT_GCC_DOESNT" definition (from ams's answer) really extsts and it called __CDT_PARSER__. For example:

#ifdef __CDT_PARSER__
#define __FILE__                "<file>"
#define __LINE__                (-1)
#define __DATE__                "<date>"
#define __TIME__                "<time>"
#endif // #ifdef __CDT_PARSER__

Hope this will be helpful.




回答2:


I've not tried it, and I've not used Eclipse for some time, but here's an idea:

In the CDT settings for Eclipse (or maybe just your project) set up a predefined macro (I seem to remember you can tell it what the compiler auto-defines) named __attribute__ that takes one parameter, and expands to nothing.

Maybe I haven't explained that right. Let me try again with an example. Basically, the aim is to define a macro that works like this:

#if ECLIPSE_THINKS_THIS_IS_SET_BUT_GCC_DOESNT
#define __attribute__(X) /* nothing */
#endif

but without putting anything actually in your code.




回答3:


Project->Properties->C/C++ general->Path and Symbols->Symbols

Add-> 
     Name: __attribute__(X)
     Value: (leave blank)

Related links: You can use this technique basically with any offending keyword




回答4:


ziu's answer is also working for XC8 Microchip compilers

Name: __interrupt
Value: (leave blank)

The function prototype now is clean:

void __interrupt ISRs(void);

And Eclipse won't complain about it.



来源:https://stackoverflow.com/questions/7968217/eclipse-cdt-syntax-error-on-attribute-keyword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!