Re: OR'd conditions.....
Posted in 1993
In <1r8v0cINNesf@emory.mathcs.emory.edu> mark@cdin-1.compu.com writes: >Fellow Netters...... > I ran into a "problem" that I found somewhat disturbing and wanted to alert >others to this..... > If you have OR'd conditions in an "IF" statement, ***ALL*** conditions are >checked regardless of the status of the 1st condition. In "C" (and most other >languages that I know), if the 1st condition is TRUE, then the remaining >conditions are skipped since the entire statement MUST logical to TRUE. >EXAMPLE: >DEFINE add_mode SMALLINT >MAIN > LET add_mode = TRUE > IF add_mode OR upd_ok() THEN > <do stuff....> > END IF >FUNCTION upd_ok() > <do stuff.....> >RETURN (either TRUE or FALSE) >END FUNCTION > In the above example, upd_ok() is ALWAYS called. Now, I reviewed the >.ec file created during compile and I can see WHY it is always called. What >I don't understand is why Informix implemented it this way?? There can be >significant overhead in calling a function even if its results aren't needed >(or in my case even desired). > Has anyone ever run into this before or had trouble with this??? Not really, since I always assume that a language evaluates both expressions, unless the documentation explicitly states otherwise. Admittedly the current 4GL documentation does not appear to be explicit on this, although my memory believes that older documentation used to be! graeme -- Disclaimer: The author's opinions are his own, and not necessarily those of Pyramid Technology Ltd. or Pyramid Technology Inc. --------------------------------------------------------------------------- -m------- Graeme Sargent Voice: +44 (0)252 373035 ---mmm----- Senior Database Consultant Fax : +44 (0)252 373135 -----mmmmm--- Pyramid Technology Ltd. Telex: Tell who??? -------mmmmmmm- Farnborough, Hants GU14 7PL Email: graeme@pyra.co.uk --------------------------------------------------------------------------- We have the technology. The tricky bit is learning how to use it.