This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu 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]

Re: gcc -O -Wconversion with glibc2 - warnings from headers.


On 29 May 2000, Oleg Goldshmidt wrote:

[ snip ]

> Here is the situation. We have a requirement that our C code should
> compile with the strictest possible set of gcc warnings.  In

[ snip ]

> We get superfluous warnings using -Wconversion with optimization from
> a couple of include files that come with glibc-devel-2.1.3-15.

[ snip ]

> /usr/include/bits/mathinline.h:431: warning: passing arg 1 of `__builtin_fabsf' as `float' rather than `double' due to prototype

The problem is that you are using warnings that are not intended to be
``strict''. The -Wconversion option has a narrowly defined, specific purpose,
and that purpose is not to find errors in modern C programs.

The purpose of -Wconversion is to find potential errors in programs which are
written in a mixture of ANSI C prototypes and old-style function definitions.
Many traditional freeware programs are this way. Also legacy programs that are
undergoing a conversion to ANSI C are like this too.  The warning helps you
spot instances where a prototype forces a different conversion than what would
otherwise take place in the absence of a prototype.

Consider something like:

    extern int foo(char c);

which corresponds to a definition

    int foo(c)
    char c;
    {
	/* ... */
    }

There is an error with the way the prototype was done; according to the
old-style rules, the parameter to the old style function must have the promoted
type of char---in other words int.

I think that -Wconversion would spot this problem in a call like

    foo('a');

where the int type parameter is being converted to char, where in the
absence of a prototype it would just remain int.

Moral of the story: not all gcc warnings are designed to generally enforce good
programming. Many of the ones that are not enabled by -Wall should be only
judiciously applied.


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