[splint-discuss] glib header and empty #define's

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Feb 28 16:28:18 PST 2008


On 27 Feb 2008, at 12:19 pm, 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
>

The semicolons for G_BEGIN/END_DECLS bother me a lot.
Suppose you have
	#include <stdio.h>
	G_BEGIN_DECLS
	extern int x;
	extern void foo(char *);
	G_END_DECLS
The result will be legal C++ or *illegal* C:
	;
is *not* a legal declaration in C.

> 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

Why do you think the expansion should be empty when you have shown that
the definition is a semicolon?

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

Try removing the semicolons from the #define directives; C *statements*
end with semicolons or curly braces, but preprocessor *directives*  
are not
statements and are terminated by newlines, not semicolons.




More information about the splint-discuss mailing list