This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bizarre warning about width of argument

Trevor Jenkins <> 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.

     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

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 (             <>

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