Pedro Izecksohn <[EMAIL PROTECTED]> wrote:
> --- Thomas Hruska wrote:
> > peternilsson42 wrote:
> > > Pedro Izecksohn <[EMAIL PROTECTED]> wrote:
> > >> peternilsson42 wrote:
> > >
> > > [ unsigned short int a;
> > > a = USHRT_MAX; /* previously a = -1; */ ]
> > >
> > >>> So you made absolutely _no_ change to the semantics of
> > >>> that assignment!
> > >> 
> > >> I fixed the signal to make others happy.
> > >
> > > You must be referring to Thomas' comment:
> > >
> > > "BTW, you should have your compiler warnings turned up
> > > so that you get a warning for assigning a signed value
> > > to an unsigned variable."
> > >
> > > Admittedly assigning -1 to an unsigned type may look
> > > unintuitive, but it's actually the best way to get the
> > > max value without using (the ugly) UXXXX_MAX macros.
> > >
> > > So, I disagree with Thomas if he is saying that a = -1;
> > > is undesirable. Although I'm all for warnings about
> > > comparison of signed and unsigned types. [e.g. -1 < 1u,
> > > which is actually false.]
> > 
> > I was actually thinking more along the lines of a forced
> > typecast once the warnings were turned up high enough:
> > 
> > a = (unsigned short)-1;

If the purpose is to get the maximum value a can have into
a, then this isn't robust with respect to changing type.

> > There would also have been warnings on the next line of
> > code with the compiler complaining about a "signed to
> > unsigned conversion" or something like that. That would
> > have been the more useful clue to the OP that a "weird
> > conversion" was happening behind the scenes.
> 
>   Yeah, gcc -Wconversion does not warn about it.
> 
>   Nice comment.
> 
>   May I report this to the gcc maintainers?

What are you reporting?

  "-Wconversion Warn for implicit conversions that may alter
   a value. ... "

Integral promotions don't alter the value.

Maybe you need -Wsign-conversion

-- 
Peter

Reply via email to