ctypes pointer from offset into array?

C

Carl Banks

Is there a way to get the pointer to an array offset in ctypes.
Example, say I define an array like so:

xfer = (c_char*bufsize)()

How would I get a pointer to then nth byte (equivalient of &xfer[n])?
I guess I would have expected xfer+n to work, but it doesn't.


Carl Banks
 
S

sturlamolden

Is there a way to get the pointer to an array offset in ctypes.
Example, say I define an array like so:

xfer = (c_char*bufsize)()

How would I get a pointer to then nth byte (equivalient of &xfer[n])?
I guess I would have expected xfer+n to work, but it doesn't.

See:
http://bugs.python.org/issue6259


For now, we can still work with char* by casting them to an integer:

# cast to pointer


# obtain address
36279232

# add offset to pointer
<ctypes.LP_c_char object at 0x02B0FDA0>


# byref also takes an offset
<cparam 'P' (022993CA)>
 
S

sturlamolden

Is there a way to get the pointer to an array offset in ctypes.

Could also mention that Cython has pointer arithmetics. Cython can be
easier to use than ctypes, but is not a standard module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top