问题
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:
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!
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 here
and 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