[splint-discuss] [splint-discuss glib header and empty #define's
Richard A. O'Keefe
ok at cs.otago.ac.nz
Thu Feb 28 17:06:05 PST 2008
> At least using the gcc compiler, the difference between a blank
> string and a
> semicolon in that context seems insignificant (they both compile,
> and they
> both do nothing. I'm not sure if there are any technicalities
> involved,
> however.)
(a) What you are talking about is NOT a blank string " " or an empty
string ""
but an empty right hand side or empty expansion.
(b) Accepting ";" as a declaration is a gcc extension. According to
both the
old (C89) and the new (C99) C standards, it is an outright
syntax error.
No ifs, buts, maybes, or technicalities: it's just not part of
the language.
(c) Most annoyingly, 'gcc -ansi' does not report this mistake in the
header.
What is the point of a command line switch to enforce a standard
if it
doesn't enforce the standard? You have to use 'gcc -ansi -
pedantic' to get
warning: ISO C does not allow extra ';' outside of a function
but at least gcc *will* tell you this if you beg hard enough.
It looks as though the header in question was written by someone
pretty clueless.
>
>> (I have no idea why the author of that header has them expand to
>> semicolons; I can't offhand think of any situation where a linkage
>> declaration would be appropriate in C++ and a semicolon would be
>> needed
>> in C. But a lot of GNU code is rather poor C.)
I can't think of any place where a linkage declaration would be
appropriate
in C++ and a bare semicolon would even be *legal* in standard C.
>
> I went to re-produce this error, with a file "test.c" containing
> #include <glib/glib.h>
> int main {return 0;}
> (which is all I needed to cause the error before).
> Which I proceeded to (attempt to) compile using the command
> gcc -l glib-2.0 test.c 2>&1|less
I wonder how experienced you are with gcc?
To get gcc to do anything resembling decent error reporting you need
at a *minimum*
gcc -ansi -pedantic -O2 -Wall
There are plenty of other -W options you may wish to enable that are not
included in -Wall. Some of the defects -Wall detects are only enabled
if you have at least -O2.
More information about the splint-discuss
mailing list