[Pyrex] Pyrex and char *x[]

Greg Ewing greg.ewing at canterbury.ac.nz
Thu May 17 00:36:59 UTC 2007


Matt Hammond wrote:

> A separate issue: I'm not sure if this comparison will work:
> 
>      if ptr.pkgname == in_pkgname:
> 
> I'd guess what happens is that in_pkgname gets typecast to a char*,  
> thereby making it comparable with ptr.pkgname.

Actually, it doesn't -- if you compare a Python string
with a char *, a temporary Python string is constructed
from the char * and then a Python comparison is done.
(The general rule is that in an operation involving a
Python and a non-Python value, Pythonicness wins.)

However, if comparing the contents of the strings is
what is intended, it's more efficient to use strcmp().

--
Greg



More information about the Pyrex mailing list