This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Bizarre warning about width of argument
- From: Russ Allbery <rra at stanford dot edu>
- To: Gnu Compiler Collection Hackers <gcc at gcc dot gnu dot org>
- Date: Thu, 26 Dec 2002 19:16:29 -0800
- Subject: Re: Bizarre warning about width of argument
- Organization: The Eyrie
- References: <Pine.LNX.4.44.0212270235270.30771-100000@suneidesis>
Trevor Jenkins <trevor.jenkins@suneidesis.com> writes:
> When the following example is compiled we get a warning:
> foo.c: In function `foo':
> foo.c:8: warning: passing arg 1 of `bar' with different width due to prototype
> This test case is extracted from a large system where these "errors" are
> being reported all over the place. The gcc comand being used is
> gcc -c -ansi -fno-nonansi-builtins -Wshadow -Wconversion foo.c
> and here's the simplest test case we can find as foo.c:
> #include <string.h>
> void foo(unsigned short);
> void bar(unsigned short);
> void foo(unsigned short zindex)
> {
> bar(zindex);
> }
> void bar(unsigned short a)
> {
> }
The warning is correct for what -Wconversion is for. You probably don't
want to use this flag with regular programs.
`-Wconversion'
Warn if a prototype causes a type conversion that is different
from what would happen to the same argument in the absence of a
prototype. This includes conversions of fixed point to floating
and vice versa, and conversions changing the width or signedness
of a fixed point argument except when the same as the default
promotion.
In other words, -Wconversion produces a warning if the presence of a
prototype causes an argument to be converted to a different type than if
there hadn't been a prototype. It's intended for helping in converting
K&R C to ANSI C. In your test case above, without a prototype the
unsigned short variable would be promoted to an int.
-Wconversion produces warnings about perfectly valid and stylistically
correct ANSI C.
--
Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>