nmm1@cus.cam.ac.uk (Nick Maclaren) writes:
|>
|> This is legal, if insane. What is worse, is that strlen is allowed to
|> set errno at whim (C99 7.5 paragraph 3), which makes the whole
|> function effectively unoptimisable.
|>
|> The compiler is allowed to know about strlen, but this sort of
|> thing means that it is usually almost impossible to determine
|> whether aliasing can occur without at least global analysis (which,
|> inter alia, means no pre-compiled, external libraries). Not nice.
|>
|> [It seems to me that since the compiler is allowed to treat strlen() as
|> a special case, part of the special case could include knowledge that its
|> version of strlen doesn't change errno. -John]

Yes, precisely. What this often means is that (say) replacing strcmp
by your own version of strcasecmp can unexpectedly reduce performance
by a very large factor, even if that call is not in the critical loop
and it is faster than the system supplied version of strcmp! The
performance can often be restored by including the function in the
module you are using it from, or by similar tricks.

This means that optimisation of C90 is very dependent on the
programmer having written his code in the right way for that
particular compiler, and that writing efficient code is very dependent
on knowing how the optimiser works. Much more so than for (say)
Fortran.