This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Implicit conversion from 32bits integer to 16bits integer (GCC 4.3.3)
- From: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- To: Frederic Belouin <frederic dot belouin at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 10 Mar 2009 15:36:13 +0100
- Subject: Re: Implicit conversion from 32bits integer to 16bits integer (GCC 4.3.3)
- References: <21fb03090903100718p5124233cn59452c54477fb1a1@mail.gmail.com>
2009/3/10 Frederic Belouin <frederic.belouin@gmail.com>:
> Hello,
>
> I would like to have a warning when there is an Implicit conversion in
> source code:
This is a question for gcc-help.
> uint32_t foo = 2000;
>
> uint16_t bar = foo;? //--> Warning Implicit conversion from uint32_t
> to uint16_t....
>
> uint16_t bar2= (uint16_t) foo; // --> no warning.
>
>
> I now that -Wtraditional-conversion in GCC 4.3.x is able to show this
> message,
It should not. Does it really? Can you provide a complete preprocessed testcase?
> but it also display warning for function implicit conversion:
> Is it possible to have only warning for implicit conversion for
> variable and not for prototype?
You did not understand what -Wtraditional-conversion does:
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
-Wtraditional-conversion (C and Objective-C only)
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.
It means that, if there was no prototype for foobar, there would be a
type conversion different from what occurs given the prototype, and
that is what Wtraditional-conversion warns.
What you want is -Wconversion. http://gcc.gnu.org/wiki/NewWconversion
Cheers,
Manuel.