The `value` of a c_char_p or c_wchar_p pointer is a Python bytes or str object. Since `value` won't consistently be the address value, it may be better to introduce a read-only `as_void` attribute that can be implemented consistently for all pointer types (including function pointers). Its value would be the same as the `value` of a casted c_void_p (e.g. NULL is mapped to None). The new attribute would be added as a getset descriptor in Pointer_getsets and PyCFuncPtr_getsets. For simple pointer types, it would have to be added specially in PyCSimpleType_new.
Related: http://bugs.python.org/issue27274. Maybe ptr.toaddress? As opposed to addressof(ptr). I think ptr.address might be confusing as it's intutive meaning is closer to addressof(ptr).
Eryk Sun’s as_void suggestion sounds similar to doing: ctypes.cast(any_pointer, ctypes.c_void_p) Why do you want the address? Perhaps it is good enough to get it from a void pointer: ctypes.cast(any_pointer, ctypes.c_void_p).value Maybe “pointer_value” would be less confusing than “toaddress”.
Martin, there were two reasons: 1. Conciseness: addressof(p.contents) vs. p.value. 2. Uniformity: I expect the value of a pointer to be the address it points to. Then Eryk pointed out that p.value has already another meaning for simple pointer types, so (2) can't be fully achieved and for (1) it will be necessary to pick another attribute name. But we could still get something shorter and uniform inside the subset of pointer types. p.as_void makes me expect a c_void_p instance. In that case the address will be p.as_void.value (or p.as_void().value?), which is a bit indirect. I think p.toaddress conveys the exact meaning[1] and consistently follows the naming style of addressof, besides being slightly shorter. [1] Well, toaddress might mean "get the pointed-to address" or "convert from pointer to address", but in any case the meaning is right.