Hi
Do you know how can I make splint ignore where I declare my variables?
I know that the old school c tells you to declare variables right at the beginning in every function, but since I am a bad person I like to declare things close to where I use them. A good example is to put int i; right before the for(i=0;...).
Let's take a very simple example
#include <stdio.h>
int main()
{
printf("Hello splint test\n");
int i;
for(i=5;i>0;i--)
{
printf("%2d...\n",i);
}
return 0;
}
Here splint and most old c compilers would like to move int i; up one line, or to put {} round the declaration and the for loop.
And now to the question, how do I turn off this check? But keep the other checks that is good?
Thanks Johan
Note 1: I already use gcc warnings(see below) as a first line off defence, and valgrind as the second. But I'm thinking about adding splint to my list of things that could control my stupidity ;-) But this check is just annoying,
The gcc warnings I use: -Wall -W -Wextra -Wconversion -Wshadow -Wcast-qual -Wwrite-strings -Werror
Note 2: I know about the potential portability problems that could come from that bad behaviour. But I feel that it increases readability, aka not needing to jump up and down to search for this type off declarations is more valuable (and this we can discuss in another thread).
Update: A little more information, I put the above code in a file called main.c. Platform used is Ubuntu 8.04 and gvim as editor, and this is the output from splint when I run it:
splint +gnuextensions main.c
Splint 3.1.1 --- 03 Nov 2006
Command Line: Setting +gnuextensions redundant with current value
main.c:8:8: Parse Error. (For help on parse errors, see splint -help
parseerrors.)
And this opens up 2 more questions that I did not think about before.
"redundant with current value", what current value?
Why is it a parse Error and not a warning?
Update:: There is a posibility to patch splint to support this problem, I have not tried this but yet but I think that it is the solution.