Eclipse CDT syntax error on __attribute__ keyword

2019-04-16 04:15发布

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.

4条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-16 04:51

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楼-- · 2019-04-16 04:51
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楼-- · 2019-04-16 05:10

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.

查看更多
冷血范
5楼-- · 2019-04-16 05:10

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.

查看更多
登录 后发表回答