public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* -Wconversion not right (<32 bit problem)
@ 1997-10-02 18:48 J. Kean Johnston
  1997-10-02 22:03 ` Jim Wilson
  0 siblings, 1 reply; 3+ messages in thread
From: J. Kean Johnston @ 1997-10-02 18:48 UTC (permalink / raw)
  To: EGCS Mailing List, GCC2 Mailing List

Hi all.

In both GCC2 and egcs, this simple (and to my eyes valid) case produces
the warning:
bw.c: In function `test':
bw.c:13: warning: passing arg 1 of `foo' with different width due to prototype

<snip>
typedef unsigned short u_short;

extern u_short foo(u_short);
extern void test(void);

u_short foo(u_short bar) {
  return bar;
}

void test(void)
{
  u_short x,y=0;
  x = foo(y);
}
<snip>

This is wrong. The function is declared to take a u_short, and a u_short
is passed. The same warning is emitted for u_char too. It seems to be for
any entity < 32 bits. Does this imply that even though I am passing a
16 bit quantity, a 32-bit quantity is pushed on the stack? If so this is
BAD news.

JKJ



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -Wconversion not right (<32 bit problem)
  1997-10-02 18:48 -Wconversion not right (<32 bit problem) J. Kean Johnston
@ 1997-10-02 22:03 ` Jim Wilson
  1997-10-03 12:45   ` J. Kean Johnston
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Wilson @ 1997-10-02 22:03 UTC (permalink / raw)
  To: J. Kean Johnston; +Cc: EGCS Mailing List, GCC2 Mailing List

What -Wconversion is doing is telling you that the code has different
semantics with the prototype than it does without the prototype.

This does not mean the code is wrong.

What this means is if you started with K&R C code, and added a prototype,
and expected to get the same program, then you added the wrong prototype.

However, if you had ANSI C code all along, then the warning may not be
telling you anything useful.

Part of the problem here is that -Wconversion does two different things:
1) It emits warnings for ANSI C code using questionable constructs.
2) It emits warnings that are useful for people converting K&R C code to
   ANSI C.

It was a historical error that the two different things got mixed together
in a single option.

	 Does this imply that even though I am passing a
	16 bit quantity, a 32-bit quantity is pushed on the stack? If so this is
	BAD news.

Yes, gcc does pass a 32-bit quantity, because that gives more efficient code,
and is compatible with how other x86 compilers work.

Pushing a 2 byte quantity to the stack is not very useful, because that would
cause the stack to become unaligned.

Most compilers work this way.  Parameters are always passed as values which
are a multiple of the word size.

Jim

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -Wconversion not right (<32 bit problem)
  1997-10-02 22:03 ` Jim Wilson
@ 1997-10-03 12:45   ` J. Kean Johnston
  0 siblings, 0 replies; 3+ messages in thread
From: J. Kean Johnston @ 1997-10-03 12:45 UTC (permalink / raw)
  To: Jim Wilson; +Cc: EGCS Mailing List, GCC2 Mailing List

On Thu, 2 Oct 1997, Jim Wilson wrote:

> Part of the problem here is that -Wconversion does two different things:
> 1) It emits warnings for ANSI C code using questionable constructs.
Perhaps this should be what -Wconversion reports. But I question whether
the code really is questionable or not. It is well casted and prototyped.
Given the original sample, the code is clean and should not emit a
warning at all, especially in -ansi or -pedantic mode. At best (see below)
it should emit a warning if -Wtraditional is specified.

> 2) It emits warnings that are useful for people converting K&R C code to
>    ANSI C.
And This should be moved to -Wtraditional

JKJ


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-10-03 12:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-02 18:48 -Wconversion not right (<32 bit problem) J. Kean Johnston
1997-10-02 22:03 ` Jim Wilson
1997-10-03 12:45   ` J. Kean Johnston

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).