Hi, > Here's a case where it WOULD matter: > > char a = 0xFF; > char b = a+1; > > if((a+1) == b) > > Here, a is promoted. a+1 = 0x100 which is NOT equal to b (which is > 0x00). If you don't want it to get promoted (i.e. you want > the special > truncating behaviour, which is unintuitive of course and therefore > rightly not the default), just cast it to a char or use &0xFF (which, > again, any decent compiler should interpret as a cast and avoid all > overhead). > > -- > Hector Martin (hector@marcansoft.com) > Public Key: http://www.marcansoft.com/marcan.asc > Would it really? Isn't variable 'a' a char which is by default a signed int8 (unless the appropriate compiler flag is set). Therefore sign extending a==0xff (-1) should still make a -1 (now 16 bits) which means the condition would still be true even after promotion. If anything it supports the 'concept' that promoting integers inside conditionals is a holdover from the original PDP10 16 bit C compiler and really shouldn't be done on an 8 bit micro-controller unless internally the 8 bit device is really a 16 bit device. The flag is there on the MCC18 compiler because there are some who would complain aggressively that without it the compiler isn't ANSI compatible but since most applications are targeted at the special features of a micro-controller, portability is probably the _least_ important part of a project when it's designed for an embedded system. I do think the compiler is in error when it makes (16*16) equal to 0 if it's assigned into a 16 bit integer. But the compiler authors are probably following some other obscure rule to maintain compatibility at the micro level with the mainframe C compiler definitions. If it didn't do this someone else would complain. I stand by a premise I've made in other postings in regards to writing for micro-controllers. Check what the particular compiler produces for code and if size or speed are an issue, write your software and define your variables to suit what the compiler does and don't get hung up on ANSI. After all, otherwise you'd have to write in assembler. 8-( John > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist