ctypes pointer to structure memory swap

Nobody nobody at nowhere.com
Fri Mar 18 17:48:53 EDT 2011


On Fri, 18 Mar 2011 10:34:35 -0700, Wanderer wrote:

> I'm observing some strange behavior with ctypes. I created this test
> code to try to figure out what I'm doing wrong creating pointers to
> structures.

What makes you think that you're doing anything wrong.

Note that the hex number shown when printing a ctypes object is the
object's ID (as per the id() function). This is typically the address of
the Python object. It is not the address of the structured data nor (in
the case of a ctypes pointer) the value of the pointer.

If you want to see the actual value of a ctypes pointer, cast it to
c_void_p then examine the .value field, e.g.:

	p = pointer(x)
	print hex(cast(p, c_void_p).value)





More information about the Python-list mailing list