views:

476

answers:

4

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.

  1. "redundant with current value", what current value?

  2. 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.

+2  A: 

Usually, with splint, if something can be suppressed it will say "suppress this with +thisflag or -thisflag"

You might try splint +gnuextensions foo.c , which turns on (most) GNU/GCC extensions that splint would otherwise take issue with.

I use splint almost as frequently as I use valgrind.

Edit:

As others have said, your running into the parser (not the analyzer), so flags really aren't going to help in this case.

Tim Post
-"Command Line: Setting +gnuextensions redundant with current value", there is something blocking.
Johan
+2  A: 

I'm not familiar with splint, but from their FAQ:

Splint is independent from your compiler. It checks standard C code, according to the ISO C99 specification. Splint supports most, but not all, of the C99 extensions to the ANSI C. Splint supports some of the gcc compiler extensions (if +gnuextensions is used).

The position of your declaration is perfectly compliant under C99, so perhaps you could consider this a bug in splint. Or it's one of the "extensions" not yet supported by splint. Either way they may be interested in your feedback. There should be no reason for a C99-compliant lint tool to complain about variable declarations.

Dan Olson
+3  A: 

This thread on the Splint mailing list discusses the issue.

It seems that the parser is mostly C89/C90, only the library seems to be C99.

Since the issue is with the parser you can't make it go away by setting flags.

starblue
I think you are correct, however I send a mail to that list to find out. http://www.cs.virginia.edu/pipermail/splint-discuss/2009-March/001288.html Let's see what happens.
Johan
+2  A: 

Here's a patch: http://www.cs.virginia.edu/pipermail/splint-discuss/attachments/20080718/52cc25f6/attachment.obj

You should be able to feed that through patch -p2 if you're in the splint/src directory, and then it should just rebuild.

That's from this email: http://www.cs.virginia.edu/pipermail/splint-discuss/2008-July/001190.html

(Sorry about the spacing on that.)

You'll find that eventually if you follow the thread starblue linked to, but I thought I'd jump to the end for you.

Splint seems to be without a maintainer right now, unfortunately. I'd consider stepping up and doing some more if I weren't so busy.

Jake