[splint-discuss] glib header and empty #define's
Brian Quinlan
brian.quinlan at iolfree.ie
Wed Feb 27 11:20:47 PST 2008
On Tue, 2008-02-26 at 15:19 -0800, Jack T Mudge III wrote:
> Greetings!
>
> This is my first message on this list. I've never used splint before
> (although I just finished perusing the manual somewhat, and the program
> appears enticing enough to be worth some work).
>
> I'm developing a small program to help me organize my homework a bit, and
> thought I'd give splint a try with it. Created some source code that
> compiles and runs flawlessly, but can't get past the glib header file
> (parse error). I realize one option is to skip the header file alltogether,
> but splint complains about unknown identifiers, and dies when I try to
> treat an int (which was defined as a GString, but defaulted to int when
> splint didn't know what a GString was, apparently) as a struct, and try to
> dereference it.
>
> I did some hunting, and I'm pretty sure I narrowed the problem down to this:
>
> in /usr/include/glib-2.0/glib/gmacros.h
> /* Guard C code in headers, while including them from C++ */
> #ifdef __cplusplus
> # define G_BEGIN_DECLS extern "C" {
> # define G_END_DECLS }
> #else
> # define G_BEGIN_DECLS ;
> # define G_END_DECLS ;
> #endif
>
> This file is included by every other header in the glib library, in this
> case specifically in /usr/include/glib-2.0/glib/gtypes.h (which I included
> in my source file). The point of this snippet seems to be to keep some
> declarations from causing problems for C++ compilers, which is fine. I
> generally don't use C++, so I'm not as familiar with some of these idioms.
>
> The definition G_BEGIN_DECLS and G_END_DECLS, then, should be "" in my
> source file -- __cplusplus is NOT defined. However, splint feeds me this
> error instead of skipping over it (since a blank definition does nothing):
>
> /usr/include/glib/gtypes.h:41:8: Parse Error: Non-function declaration:
> G_BEGIN_DECLS : int. (For help on parse errors, see splint -help
> parseerrors.)
>
> I have tried adding #define G_BEGIN_DECLS ; to my source file, and splint
> complains about a duplicate definition (so apparently it's getting to the
> definition in the first place). Unfortunately, I'm out of ideas except for
> removing this code from my header files (since I'm not using C++, it
> shouldn't do any harm to do that, but it seems drastic to me).
>
> Does anyone have some ideas as to how to get splint past these defines?
> _______________________________________________
> splint-discuss mailing list
> splint-discuss at mail.cs.virginia.edu
> http://www.cs.virginia.edu/mailman/listinfo/splint-discuss
Hi Jack,
In the past when faced with similar parse problems, I've found it useful
to use +keep on the splint command-line. See "Debug flags" at the bottom
of:
http://www.splint.org/manual/html/appB.html
This keeps the temporary files (e.g., preprocessor output) generated by
splint. This will show you exactly what splint is failing to parse.
Perhaps more importantly, it might also give you an idea as to why
splint is seeing the preprocessed code in this way.
Bye,
Brian
More information about the splint-discuss
mailing list