public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Russ Allbery <rra@stanford.edu>
To: Gnu Compiler Collection Hackers <gcc@gcc.gnu.org>
Subject: Re: Bizarre warning about width of argument
Date: Fri, 27 Dec 2002 03:37:00 -0000	[thread overview]
Message-ID: <ylsmwktalu.fsf@windlord.stanford.edu> (raw)
In-Reply-To: <Pine.LNX.4.44.0212270235270.30771-100000@suneidesis> (Trevor Jenkins's message of "Fri, 27 Dec 2002 02:42:33 +0000 (GMT)")

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

  reply	other threads:[~2002-12-27  3:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-27  3:31 Trevor Jenkins
2002-12-27  3:37 ` Russ Allbery [this message]
2002-12-28 19:50   ` [GCC] " Trevor Jenkins
2002-12-28 20:30     ` Russ Allbery

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ylsmwktalu.fsf@windlord.stanford.edu \
    --to=rra@stanford.edu \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).