What to do after Python?

Roy Smith roy at panix.com
Sun Feb 18 20:53:38 EST 2001

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?).

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 

The most interesting case was Linux with -O.  I don't know i86 assembler, 
so I'm guessing a bit here, but seems to have in-lined the strlen function, 
eliminating the subroutine call completely.  It still left what looks like 
two code fragments to count the length of the string.

More information about the Python-list mailing list