What to do after Python?
Erno Kuusela
erno-news at erno.iki.fi
Mon Feb 19 00:02:50 EST 2001
In article <roy-770A13.20533818022001 at news.panix.com>, Roy Smith
<roy at panix.com> writes:
| Erno Kuusela <erno-news at erno.iki.fi> wrote:
|| | if (length = strlen(s))
|| | s[length-1] = 0;
||
|| | and cut your instruction count in half :-)
||
|| a sensible optimising compiler will generate identical code for both.
| I will admit that my compiler theory is a bit rusty, but it's hard to see
| how a compiler would know that the strlen function would return the same
| value when called again with the same argument (idempotent?).
it's part of the language, so the compiler is allowed to have
special knowledge about it.
| In any case, I just tried it on my Linux box (GNU compiler) and on a
| Solaris machine (Sun Workshop compiler). Neither compiler generated the
| same code for the two versions, regardless of whether optimizing was turned
| on or not. Both generated two strlen stanzas (see below), with or without
| -O.
i guess they are not sensible then ;)
at least the cc/libc combo on linux does have special knowledge about
many functions, including strlen, but i guess this case has not been
considered important enough to bother with.
look in /usr/include/bits/string.h on your linux box and
at <URL:http://puffin.external.hp.com/lxr/
source/gcc/gcc/builtins.c#L1306>...
-- erno
More information about the Python-list
mailing list