char* arguments in C API

"Martin v. Löwis" martin at v.loewis.de
Sun Mar 23 18:56:10 CET 2003


> The Python API declares most of its functions that take a C string using
> char* (as opposed to const char*). This results in a warning in stricter
> compilers if you do something like

Is there any chance that the "slightly stricter compiler" is a C++ 
compiler, as opposed to being a C compiler? If not, which compiler
is it, and what precisely is its message?

> Is there an alternative to this slightly ugly hack? 

I suggest using a C compiler if you need an alternative now.

> Shouldn't parameters like these be const char*? 
 > Or is it just an historical thing?

It's mostly historical, and also irrelevant for C. For C++ users
of the Python API, a number of these functions have been changed
to const char*. Please understand that changing a single function
in that way will cause dozens of changes if done properly, as now
the parameter will be const char*, so the function will fail to
compile if it passes the parameter to functions expecting char*.

With that in mind, feel free to submit patches changing the API.
It is fine to change as much as needed, as long as existing code
won't be broken. You should start, in any case, with the Python
CVS, since it already has const char* in a few more places.

Regards,
Martin






More information about the Python-list mailing list