home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!unipalm!tim
- From: tim@unipalm.co.uk (Tim Goodwin)
- Subject: Re: Order of evaluation?
- Message-ID: <1992Nov6.125409.23455@unipalm.co.uk>
- Organization: Unipalm Ltd., 216 Cambridge Science Park, Cambridge CB4 4WA, UK
- 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>
- Date: Fri, 6 Nov 1992 12:54:09 GMT
- Lines: 22
-
- Josef Moellers <mollers.pad@sni.de> writes:
-
- >My understanding was (and still is), that functions need only be called
- >as far as necessary.
- >E.g. in an expression like
- > a() * b() * c() * e() * f() * g()
- >the compiler might decide to generate code to test the intermediate
- >result to be 0, in which case the rest of the expression might be
- >dropped.
-
- No. C operators are eager, that is, they always evaluate all their
- arguments. (The exceptions, which were mentioned earlier in this
- thread, are || and &&, which might be better thought of as flow control
- constructs. Perl and sh programmers tend to think of them in this way.)
-
- In the quoted example, each of the functions must be evaluated (although
- there is no guarantee about the order in which they are evaluated). It
- is possible that the compiler might avoid some of the multiplications,
- if it happens to notice that they are unnecessary, but it may not omit
- any of the function calls.
-
- Tim.
-