index and rindex question...

Karl Heuer karl at haddock.ima.isc.com
Thu Feb 15 15:48:50 AEST 1990


>> 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 at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list