Is it guaranteed that this statement evaluates from left to right and evaluation stops as soon as there is a false returned from one of the functions in the statements? Date sent: Wed, 11 Apr 2001 07:38:25 -0400 Send reply to: pic microcontroller discussion list From: Bob Ammerman Subject: Re: [OT]: Coding style To: PICLIST@MITVMA.MIT.EDU > bool _stdcall X9241Write(unsigned char address, > unsigned char instruction) > { > return > I2CStart() && > I2CTransmit(fullAddr) && > I2CGetAck() && > I2CTransmit(instruction) && > I2CGetAck() && > I2CStop(); > } > > Boolean values are first class types. > > I really get bugged by: > > if (yadayada) > b = true; > else > b = false; > > which I see in code of all sorts. > > What is wrong with: > > b = yadayada; > > As to the original question re: early returns froma function: > > I just had an argument of this yesterday with a colleague. Personally > I use this technique all the time and have no problem with it. It just > becomes one more 'idiom' in my bag of tricks. When working with my own > code know there could be early exits, so I am not stung by them. Also, > this more closely models the way we think above solving problems. > > On the other hand, when you're not expecting this it can be a _big_ > pain. So I can understand those who think this is horrible style. > > Just an aside: > > This is less of problem, IMNHO, in C++ than in C. In C++ cleanup > (destructors) still happen when you return early from a function. > > Bob Ammerman > RAm Systems > (contract development of high performance, high function, low-level > software) > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > ============================== Ruben Jvnsson AB Liros Elektronik Box 9124, 200 39 Malmv, Sweden TEL INT +46 40142078 FAX INT +46 40947388 ruben@pp.sbbs.se ============================== -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu