* -Wconversion producing incorrect warning
@ 2005-10-31 17:30 Kevin P. Fleming
2005-10-31 17:42 ` John Love-Jensen
2005-11-04 11:54 ` Segher Boessenkool
0 siblings, 2 replies; 8+ messages in thread
From: Kevin P. Fleming @ 2005-10-31 17:30 UTC (permalink / raw)
To: gcc-help
When compiling this program:
#include <sys/types.h>
#include <inttypes.h>
typedef uint16_t t;
int f(t x)
{
return x*x;
}
int main(int argc, char *argv[])
{
t b = 12;
return f(b);
}
using GCC 3.3.5, 3.4.3 and 4.0.1 with '-Wconversion' in effect, I get
this warning:
luigi.c: In function `main':
luigi.c:15: warning: passing arg 1 of `f' with different width due to
prototype
I don't understand why this is true... the prototype and the argument
are of the same type.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: -Wconversion producing incorrect warning
2005-10-31 17:30 -Wconversion producing incorrect warning Kevin P. Fleming
@ 2005-10-31 17:42 ` John Love-Jensen
2005-10-31 18:40 ` Kevin P. Fleming
2005-11-04 11:54 ` Segher Boessenkool
1 sibling, 1 reply; 8+ messages in thread
From: John Love-Jensen @ 2005-10-31 17:42 UTC (permalink / raw)
To: Kevin P. Fleming, MSX to GCC
Hi Kevin,
The ABI of your platform probably converts the uint16_t to an unsigned int
on the stack.
HTH,
--Eljay
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: -Wconversion producing incorrect warning
2005-10-31 17:42 ` John Love-Jensen
@ 2005-10-31 18:40 ` Kevin P. Fleming
2005-10-31 18:53 ` John Love-Jensen
0 siblings, 1 reply; 8+ messages in thread
From: Kevin P. Fleming @ 2005-10-31 18:40 UTC (permalink / raw)
Cc: MSX to GCC
John Love-Jensen wrote:
> The ABI of your platform probably converts the uint16_t to an unsigned int
> on the stack.
That's what I suspected, as the person who provided that code reported
that's what was causing the warning.
What concerns me is that the warning message states this is happening
because of the prototype, but that's not technically true... on a
platform that actually chose to pass the 16-bit quantity on the stack
the warning would not occur, so this is a platform-specific problem, not
anything wrong with the code itself.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: -Wconversion producing incorrect warning
2005-10-31 18:40 ` Kevin P. Fleming
@ 2005-10-31 18:53 ` John Love-Jensen
2005-10-31 19:35 ` Kevin P. Fleming
0 siblings, 1 reply; 8+ messages in thread
From: John Love-Jensen @ 2005-10-31 18:53 UTC (permalink / raw)
To: Kevin P. Fleming; +Cc: MSX to GCC
Hi Kevin,
> What concerns me is that the warning message states this is happening
> because of the prototype, but that's not technically true... on a
> platform that actually chose to pass the 16-bit quantity on the stack
> the warning would not occur, so this is a platform-specific problem, not
> anything wrong with the code itself.
Correct. On that platform, the warning is occurring because of the
platform's ABI.
The warning does not indicate that there is anything wrong with the code
itself. The warning is justified, warranted, and desirable if/when/where
-Wconversion is specified, since the warning tells you that something funny
is happening that may not be apparent from the code itself, on that
particular platform.
Sincerely,
--Eljay
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: -Wconversion producing incorrect warning
2005-10-31 18:53 ` John Love-Jensen
@ 2005-10-31 19:35 ` Kevin P. Fleming
0 siblings, 0 replies; 8+ messages in thread
From: Kevin P. Fleming @ 2005-10-31 19:35 UTC (permalink / raw)
Cc: MSX to GCC
John Love-Jensen wrote:
> The warning does not indicate that there is anything wrong with the code
> itself. The warning is justified, warranted, and desirable if/when/where
> -Wconversion is specified, since the warning tells you that something funny
> is happening that may not be apparent from the code itself, on that
> particular platform.
We've worked around it for now by just passing the arguments
by-reference instead. In this application it makes very little
difference, and may in fact be slightly faster.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: -Wconversion producing incorrect warning
2005-10-31 17:30 -Wconversion producing incorrect warning Kevin P. Fleming
2005-10-31 17:42 ` John Love-Jensen
@ 2005-11-04 11:54 ` Segher Boessenkool
2005-11-04 12:20 ` John Love-Jensen
1 sibling, 1 reply; 8+ messages in thread
From: Segher Boessenkool @ 2005-11-04 11:54 UTC (permalink / raw)
To: Kevin P. Fleming; +Cc: gcc-help
> using GCC 3.3.5, 3.4.3 and 4.0.1 with '-Wconversion' in effect, I get
> this warning:
>
> luigi.c: In function `main':
> luigi.c:15: warning: passing arg 1 of `f' with different width due to
> prototype
>
> I don't understand why this is true... the prototype and the argument
> are of the same type.
Yes, so the parameter will be passed as whatever your ABI
specifies for parameters of unsigned 16-bit type.
The problem here is, that -Wconversion does _not_ warn
about type conversions in your code! It is a warning for
people trying to port old K&R C code to ANSI C. What the
warning means is, "if there would not have been a prototype
for f() in scope, the parameter would have been passed as
a 32-bit type".
GCC does not currently have a warning with the behaviour
you might have expected, and the name of "-Wconversion"
confuses a lot of people. Perhaps we should change its
name...
Segher
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: -Wconversion producing incorrect warning
2005-11-04 11:54 ` Segher Boessenkool
@ 2005-11-04 12:20 ` John Love-Jensen
2005-11-04 12:38 ` Segher Boessenkool
0 siblings, 1 reply; 8+ messages in thread
From: John Love-Jensen @ 2005-11-04 12:20 UTC (permalink / raw)
To: Segher Boessenkool, Kevin P. Fleming; +Cc: MSX to GCC
Hi Segher,
> The problem here is, that -Wconversion does _not_ warn about type conversions
in your code!
From: http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Warning-Options.html
-------------------------------------------------------------------
-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.
Also, warn if a negative integer constant expression is implicitly converted
to an unsigned type. For example, warn about the assignment x = -1 if x is
unsigned. But do not warn about explicit casts like (unsigned) -1.
-------------------------------------------------------------------
What kind of type conversions in your code are you referring to?
--Eljay
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: -Wconversion producing incorrect warning
2005-11-04 12:20 ` John Love-Jensen
@ 2005-11-04 12:38 ` Segher Boessenkool
0 siblings, 0 replies; 8+ messages in thread
From: Segher Boessenkool @ 2005-11-04 12:38 UTC (permalink / raw)
To: John Love-Jensen; +Cc: Kevin P. Fleming, MSX to GCC
>> The problem here is, that -Wconversion does _not_ warn about type
>> conversions
> in your code!
[snip]
> What kind of type conversions in your code are you referring to?
Not my code. The type conversions I am referring to, as does
the documentation piece I snipped, is conversion of arguments
to functions specifically, and any type conversions generally.
Hrm, I think I don't understand your question :-)
Segher
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-11-04 12:38 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-31 17:30 -Wconversion producing incorrect warning Kevin P. Fleming
2005-10-31 17:42 ` John Love-Jensen
2005-10-31 18:40 ` Kevin P. Fleming
2005-10-31 18:53 ` John Love-Jensen
2005-10-31 19:35 ` Kevin P. Fleming
2005-11-04 11:54 ` Segher Boessenkool
2005-11-04 12:20 ` John Love-Jensen
2005-11-04 12:38 ` Segher Boessenkool
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).