char* arguments in C API
Julian Rockey
linux at jrockey.com
Sun Mar 23 13:45:06 EST 2003
"Martin v. Löwis" wrote:
>> 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?
Ah yes. You caught me out. I actually started off with C++, and I'm afraid
the lines between C and C++ are a little blurry for me (I unfortunately -
and, I know, very wrongly - tend to consider C as being "C++ without
classes".. :-) )
>
>> Is there an alternative to this slightly ugly hack?
>
> I suggest using a C compiler if you need an alternative now.
The module is C++ - so I guess I'll cast to char* explicitly for 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*.
I understand that completely - not a trivial job, and I appreciate it's
really just for tidyness for C++ - no tangible benefit.
>
> 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.
I read from this that the direction is to change to const char* as and when
possible. In the meantime I'll cast. And if I get really sick of it I'll
try creating some patches :-)
Thanks very much for the response. I didn't intend my query to be a
complaint - more of a "I am missing something here?" Which I was.
>
> Regards,
> Martin
cheers
Julian
More information about the Python-list
mailing list