Non-standard function return types: Fixing Splint parse error

随声附和 提交于 2019-12-14 02:40:42

问题


I'm using the embedded-system XC8 C compiler (for PIC microprocessors). The following is allowed:

bit foo(){
    //...
}

but being non-standard C, the Splint static analyser gives the following error:

Parse Error: Non-function declaration: bit : "--------------------------------------" int.

And the file/line of the error is the function prototype in the respective .h file.

How can I fix this so Splint can analyse the rest of the file(s)? I think there might be two ways:

  1. I think I remember seeing a flag which can be passed to Splint via CLI which tells it to substitute a given non-standard type to a standard type (e.g. bit to unsigned char) but I can't seem to find it at all now!

  2. Also, perhaps there is an alternative way to write the c code that satisfies ANSI-C requirements while also still allowing XC8 to interpret the return type as bit?

Progress:

I found the following on a forum, but I can't find information on how to use the -D flag in the manual:

To ignore a keyword, add -Dnonstandardkeyword= to make the preprocessor eliminate it

And

use -Dspecialtype=int to make a custom type parse as an int.


回答1:


If there's no option for the analysis program to do the substitution, you can of course do it using the preprocessor.

Have something like:

#if defined RUNNING_SPLINT
#define bit unsigned char
#endif

in e.g. a header that you make sure is included everywhere, enter code hereand make sure you define the pre-processor symbol RUNNING_SPLINT when Splint sees the code. It has a -D flag for this.




回答2:


It was in the FAQ:

http://www.splint.org/faq.html

To quote it:

16.I develop code on an embedded system with a compiler that uses nonstandard key words and data types. I would like to run Splint on my code but these nonstandard keywords cause parse errors. What should I do?

You can often use -D to solve this problem.

If you just want to ignore a keyword, you can add -Dnonstandardkeyword= to make the preprocessor eliminate the keyword, where nonstandardkeyword is the name of the keyword. Similarly, you can use -Dspecialtype=int to make a custom type parse as an int.



来源:https://stackoverflow.com/questions/21986996/non-standard-function-return-types-fixing-splint-parse-error

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