English 中文(简体)
splint failing on code that includes complex.h
原标题:

I m trying to run splint on a C source that includes complex.h from the standard C library to support complex arithmetic.

Unfortunately, splint fails with the following error.

Splint 3.1.2 --- 03 May 2009

/usr/include/bits/cmathcalls.h:54:31: Parse Error: Non-function declaration: _Complex : extern double. (For help on parse errors, see splint -help parseerrors.) *** Cannot continue.

Googling for the problem resulted in only this message on the split-discuss mailing list (which remains unanswered).

Any ideas?

Update

Here is a very simple example of a failing source:

#include <complex.h>

int main() {
  complex x = 2 + 8i;
  x = x + 1;
}

Attempts to redefine the unsupported _Complex C99 Keyword leads to an error with the imaginary part of the complex number (which isn t surprising I suppose).

lsc@deepthought:~$ splint-D_Complex=double temp.c  
Splint 3.1.2 --- 03 May 2009

 temp.c:4:20: Parse Error. (For help on
 parse errors, see splint -help
                parseerrors.)
*** Cannot continue.
最佳回答

I eventually solved this by temporarily overriding complex.h with a dummy one when calling splint.

[lsc@home]$ ls /opt/qa_tools/utils/splint_includes/
complex.h

[lsc@home]$ splint -I/opt/qa_tools/utils/splint_includes test.c
Splint 3.1.1 --- 15 Jun 2004

Finished checking --- no warnings

The dummy complex.h file suppresses the relevant keywords and replaces constants/functions with dummy ones. These keywords/constants/functions were gleaned from the specs

A copy of this file is available here: https://gist.github.com/1316366

问题回答

I m not a splint user, so take the following with a grain of salt...

The _Complex keyword was added with C99, and the splint FAQ has this to say about C99 (http://www.splint.org/faq.html#quest15):

However, Splint doesn t yet support all C99 extensions so there are some legitimate C programs that will need to be modified.

I d guess that _Complex is covered by that caveat.

You might be able to work around splint s apparent lack of support for _Complex using a technique described in the FAQ (http://www.splint.org/faq.html#quest14), but I d be surprised if this got you very far with helping splint deal with C99 code using _Complex:

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.

I was struggling to get splint to ignore headers and not finding suitable answers anywhere online. I finally used splint s built-in help, and discovered this:

#ifndef S_SPLINT_S

#endif

If you put this pair around code you want splint to ignore, it will ignore it! None of the other things work for system header files, at least that I ve found.





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签