Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!rutgers!mit-eddie!mit-amt!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: index and rindex question... Message-ID: <15947@haddock.ima.isc.com> Date: 15 Feb 90 04:48:50 GMT References: <13259.25D681F3@urchin.fidonet.org> <1748@skye.ed.ac.uk> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 14 >> any reasonably decent optimizing compiler will only call the function once > >Anyone know of a compiler that does this for functions like strchr? I was going to say that gcc has an extension to recognize pure functions, but then I realized that strchr() is not pure--its result depends on not only the value of its arguments, but also the *contents* pointed to. So, in order for a compiler to correctly optimize out a second call to strchr(), it has to not only know that strchr() is an almost-pure function (probably by recognizing it as a builtin) but it also has to prove that the pointed-to string could not have been modified between the two calls. This is a sufficiently hard problem that I doubt that any current compilers bother to check for it. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint