This is the mail archive of the libc-alpha@cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

warning floods, 2.0.97


First, this thing:

/* It is possible to compile containing GCC extensions even if GCC is
   run in pedantic mode if the uses are carefully marked using the
   `__extension__' keyword.  But this is not generally available before
   version 2.8.  */
#if !defined __GNUC__ || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)

# define __extension__          /* Ignore */

#endif

This is a crude band-aid. I actually use -pedantic, and because of this
thing, I get loads upon loads of warnings for every use of any string
functions. Are we blowing off gcc 2.7.x as obsolete, or what? I think it
could be made to work at least a _little_ better than it does now. Most of
the warnings I've seen are about the ({...}) construct, and I know
__extension__ does work in 2.7.x for those. So perhaps we should identify
exactly where __extension__ does and doesn't work, and make a bunch of
more-specific macros, like

#if gcc is 2.7.x
#define __longlong_extension__ /**/
#define __bracedgroup_extension__ __extension__
#else
#define __longlong_extension__ __extension__
#define __bracedgroup_extension__ __extension__
#endif

And use the specific __*_extension__ macros everywhere in the public headers.

Doing this just in string.h has made at least one of my programs pass through
a lot cleaner. If there's no objection to the idea, I'll do it for the rest
of the headers and make a patch.

Next problem, <string.h> doesn't even compile cleanly all by itself. With -O
on, it hits -Wmissing-prototypes 3 times and -Wcast-qual twice. Filling in
the missing prototypes should be easy. I'm not sure what to do about the
-Wcast-qual's, since some poorly-designed C interfaces basically require you
to cast away const (and strpbrk is one of them). I hope someone comes up with
a way to quiet it down, though.

/usr/include/bits/string2.h:130: warning: no previous prototype for `__mempcpy_small'
/usr/include/bits/string2.h:265: warning: no previous prototype for `__strcpy_small'
/usr/include/bits/string2.h:394: warning: no previous prototype for `__stpcpy_small'
/usr/include/bits/string2.h: In function `__strpbrk_c2':
/usr/include/bits/string2.h:798: warning: cast discards `const' from pointer target type
/usr/include/bits/string2.h: In function `__strpbrk_c3':
/usr/include/bits/string2.h:811: warning: cast discards `const' from pointer target type

Even worse, <math.h> actually fails to compile with
-O2 -ansi -pedantic -D_GNU_SOURCE.

/usr/include/bits/mathinline.h:117: warning: ANSI C forbids specifying structure member to initialize
/usr/include/bits/mathinline.h:117: initializer element for `__u.__f' is not computable at load time/usr/include/bits/mathinline.h: In function `__signbit':
/usr/include/bits/mathinline.h:122: warning: ANSI C forbids specifying structure member to initialize
/usr/include/bits/mathinline.h:122: initializer element for `__u.__d' is not computable at load time/usr/include/bits/mathinline.h: In function `__signbitl':
/usr/include/bits/mathinline.h:127: warning: ANSI C forbids specifying structure member to initialize
/usr/include/bits/mathinline.h:127: initializer element for `__u.__l' is not computable at load time

Before anybody suggests that those flags don't make sense, let me point out
this very same error (initializing an automatic aggregate with something that
is not a compile-time constant) is treated as an error by the Irix compiler.
Using -pedantic helps me write code that will not cause trouble for Irix
users. Now, -pedantic without -ansi causes some glibc headers to get
confused, so -ansi has to be there. Once you get -ansi in the mix, you lose
all the non-ANSI functions unless you ask for them. So really, -ansi
-pedantic -D_GNU_SOURCE is the only way to go. And math.h bombs on it.

I think rewriting these initializations to not use the gcc extensions will
not have any adverse effect. After all, what's the real difference between
an initialized automatic variable, and an uninitialized variable declaration
with an assignment immediately after it? I would hope they would compile to
the same assembly code.

All of the problems I've mentioned are exposed by using this test file which
includes all the standard C headers and contains no code:

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

and compiling it with all warnings enabled.

The more warning options you can pass cleanly, the better. When an
application programmer wants to voluntarily restrict himself to a cleaner
subset of C, the library should not prevent him from doing so.

-- 
Alan Curry


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]