home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16077 < prev    next >
Encoding:
Text File  |  1992-11-07  |  1.4 KB  |  33 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!unipalm!tim
  3. From: tim@unipalm.co.uk (Tim Goodwin)
  4. Subject: Re: Order of evaluation?
  5. Message-ID: <1992Nov6.125409.23455@unipalm.co.uk>
  6. Organization: Unipalm Ltd., 216 Cambridge Science Park, Cambridge CB4 4WA, UK
  7. References: <3736@dozo.and.nl> <1992Oct27.002204.11825@den.mmc.com> <josef.720691377@uranium> <1992Nov2.192805.17329@CSD-NewsHost.Stanford.EDU> <1dau8nINNk59@uranium.sto.pdb.sni.de>
  8. Date: Fri, 6 Nov 1992 12:54:09 GMT
  9. Lines: 22
  10.  
  11. Josef Moellers <mollers.pad@sni.de> writes:
  12.  
  13. >My understanding was (and still is), that functions need only be called
  14. >as far as necessary.
  15. >E.g. in an expression like
  16. >    a() * b() * c() * e() * f() * g()
  17. >the compiler might decide to generate code to test the intermediate
  18. >result to be 0, in which case the rest of the expression might be
  19. >dropped.
  20.  
  21. No.  C operators are eager, that is, they always evaluate all their
  22. arguments.  (The exceptions, which were mentioned earlier in this
  23. thread, are || and &&, which might be better thought of as flow control
  24. constructs.  Perl and sh programmers tend to think of them in this way.)
  25.  
  26. In the quoted example, each of the functions must be evaluated (although
  27. there is no guarantee about the order in which they are evaluated).  It
  28. is possible that the compiler might avoid some of the multiplications,
  29. if it happens to notice that they are unnecessary, but it may not omit
  30. any of the function calls.
  31.  
  32. Tim.
  33.