On Fri, 2 May 2014, Electron wrote: > > Hello! > > a is a signed int and contains -100 > b is an unsigned int and contains 500 > > a > Why on earth? :P > > I can cast b to signed int and get the correct results, > but leaving as is instead the result surprises me a lot, > as I have no idea why -100<500 should be false, it's like > if the compiler casts a to an unsigned type automatically > (and this was clearly not requested by the programmer). > > If we keep them as they are, i.e. the first signed and the > second unsigned, then why should a > This is very confusing really. > > Now I have to correct all of my code, looking for > comparisons between signed and unsigned ints, and cast > both variables to the type I mean. :-/ > > Is there any other situation I have to be careful about > when mixing signed and unsigned types? > > Please do not reply the obvious "generically the use of > unsigned types is not adviceable, why don't you stick > with only signed types? you will be much safer". THANKS. > > Cheers, > Mario You should switch to a language that deals with mixed signed / unsigned=20 comparisons correctly :-) XCSB does it correctly. it returns true for -1 < 255 (8 bit signed < 8 bit= =20 unsigned). Cheers Sergio --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .