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; 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. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
