This is the mail archive of the gcc-help@gcc.gnu.org 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: Implicit conversion from 32bits integer to 16bits integer (GCC 4.3.3)


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.


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