[SciPy-User] NumPy C API: where does casting pointer-to-object to pointer-to-function come from?

Yury V. Zaytsev yury@shurup....
Thu Jun 21 08:18:38 CDT 2012


I'm trying to get rid of warnings in my C++ code that extensively uses
NumPy C API. Unfortunately, with gcc 4.6 / -Wall -pedantic, NumPy 1.6.1
on Fedora Core 16 I get lots of warnings of this kind:

    warning: ISO C++ forbids casting between pointer-to-function and pointer-to-object [enabled by default]

It is generated by this kind of lines:

    PyObject* pObj;
    PyArray_Descr* typecode = PyArray_DescrFromScalar(pObj); // bang!
    int val;
    PyArray_ScalarAsCtype(pObj, &val); // bang!
    int size = PyArray_Size(pObj); // bang!

... and so on.

This is highly surprising to me, because the signatures of the functions
are as follows according to the documentation:


    PyArray_Descr* PyArray_DescrFromScalar(PyObject* scalar)
    void PyArray_ScalarAsCtype(PyObject* scalar, void* ctypeptr)
    npy_intp PyArray_Size(PyArrayObject* obj)

I suspect that I can mute these warnings with re-interpret cast gcc
extension as described here:


but I don't get it what to cast to what and where all this is coming
from. As it seems to be from the function signatures there shouldn't be
any problems with type conversion here?!

Any hints would be highly appreciated,

Sincerely yours,
Yury V. Zaytsev

More information about the SciPy-User mailing list