pjh@mccc.edu (Peter J. Holsberg) (04/06/91)
The other day I posted about operator assignments and side effects, and today received the following response that I would like your *posted* comments on. > When in doubt, use "long-hand" and let the compiler optimize. If you have > existing code which you are trying to decypher, you should write a test > program for your particular compiler because while there is a "correct" > order of evaluation, it is not necessarily adheared to. Thanks, Pete -- Prof. Peter J. Holsberg Mercer County Community College Voice: 609-586-4800 Engineering Technology, Computers and Math UUCP:...!princeton!mccc!pjh 1200 Old Trenton Road, Trenton, NJ 08690 Internet: pjh@mccc.edu Trenton Computer Festival -- 4/20-21/91
ckp@grebyn.com (Checkpoint Technologies) (04/06/91)
In article <1991Apr5.163209.25118@mccc.edu> pjh@mccc.edu (Peter J. Holsberg) writes: >The other day I posted about operator assignments and side effects, and >today received the following response that I would like your *posted* >comments on. > >> When in doubt, use "long-hand" and let the compiler optimize. ...except that the C language definition tells you when you are in doubt, by stating which constructions are "undefined". >>If you have >> existing code which you are trying to decypher, you should write a test >> program for your particular compiler because while there is a "correct" >> order of evaluation, it is not necessarily adheared to. I must interpret this to mean, if you are given a program to decode which uses undefined effects, and you must clean it up, then you need to discover the actual effects which the compiler is generating. Then you break the code into well-defined effects that the language spec guarantees. When you find a compiler which does not adhere to the "correct" order of evaluation, then it is a bad, defective compiler. As to the order of side effects in an expression, the language spec says that they're undefined in most cases (sequence is guaranteed for "," "&&", "||" but for nothing else; and by "," I mean the comma operator, NOT the comma separating function parameters) so good, correct compilers are free to interpret as they choose. -- First comes the logo: C H E C K P O I N T T E C H N O L O G I E S / / ckp@grebyn.com \\ / / Then, the disclaimer: All expressed opinions are, indeed, opinions. \ / o Now for the witty part: I'm pink, therefore, I'm spam! \/
ravim@gtenmc.UUCP (Vox Populi) (04/11/91)
In article <1991Apr6.143523.10443@grebyn.com> ckp@grebyn.com (Checkpoint Technologies) writes: ... >undefined in most cases (sequence is guaranteed for "," "&&", "||" but >for nothing else; and by "," I mean the comma operator, NOT the comma >separating function parameters) so good, correct compilers are free to >interpret as they choose. IMHO "?:" operator also guarantees a sequence point, correct if I am wrong. Just for nitpicking:- How about "," as a list separator in declarations (ex. int i = 0xff, j = i;) ? I believe this usage also results in sequence. >First comes the logo: C H E C K P O I N T T E C H N O L O G I E S / / > ckp@grebyn.com \\ / / - Ravi Mandava -- ********************** #include <stddisclaimer.h> ************************** Ravi Mandava e-mail : ravim@gtenmc.gtetele.com or ravim@gtenmc.UUCP *******************************************************************************
bhoughto@pima.intel.com (Blair P. Houghton) (04/13/91)
In article <1117@gtenmc.UUCP> ravim@gtenmc.UUCP (Ravi Kumar Mandava) writes: >IMHO "?:" operator also guarantees a sequence point, correct if I am wrong. Only the one after the expression that precedes the `?' >Just for nitpicking:- How about "," as a list separator in declarations >(ex. int i = 0xff, j = i;) ? I believe this usage also results in sequence. Appendix B of the standard lists all of the sequence points. --Blair "RTAS."