[SciPy-User] [SciPy-user] numpy and C
Charles R Harris
Wed Jun 9 08:46:19 CDT 2010
On Wed, Jun 9, 2010 at 5:38 AM, tinauser <firstname.lastname@example.org> wrote:
> Dear Charles,
> thanks for the reply.
> The part of code causing the problem was exactly this
> Pymatout_img->data= cam_frame->data;
> where Pymatout is a PyArrayObject and cam_frame is a structure having a
> pointer to undefined char data.
> The code works all right if I recast in this way
> Pymatout_img->data= (char*)cam_frame->data;
> I'm not sure if this is allowed;I guessed it works because even if
> Pymatout_img->data is always a pointer to char, the PyArrayObject looks in
> ->descr->type_num to see what is the data type.
Numpy uses char* all over the place and later casts to the needed type, it's
the old way of doing void*. So your explicit cast is fine. For some
compilers, gcc for example, you also need to use a compiler flag to let the
compiler know that you are going to do such things. In gcc the flag is
-fno-strict-aliasing but I don't think you need to worry about this in VC.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User