[C++-sig] working around the non-const Python C API

Jeremy Hylton jeremy at alum.mit.edu
Fri Dec 2 21:01:21 CET 2005

I was curious if anyone had advice on how to work around the fact that
much of the Python C API asks for char* when it really intends to
treat it as a const char*.  An example of this behavior is the
PyMethodDef struct, which has char* ml_name and char* ml_doc
parameters.  If you use a string literal, you get a warning about
casting a const char* to a char*.  I can add a cast around each
literal, but that's really ugly.

Is there a good way to avoid the warnings?

Secondarily, I know that python-dev is a bit hesitant about const
correctness, but we did get some const char* types added with the new
bytecode compiler.  Perhaps it's worthwhile to try changing a few of
the most egregious cases to use const char*.


More information about the Cplusplus-sig mailing list