I'm trying to use a c++ function, that takes a pointer as an argument, in python. For the facade I'm using pybind11 and ctypes in python in order to create pointers.
However the adress I'm getting in python isn't equal to the one in c++. I do need the adress of a variable later in the project and i cant get it by return, since the function is already returning something else.
c++ function
void myFunc(double* ptr, double value)
{
*ptr = value;
std::cout << "ptr value:\t\t" << *ptr << std::endl;
std::cout << "ptr adress:\t\t" << ptr << std::endl;
};
pybind code
m.def("myFunc",
[](double* ptr,
double value) {
myFunc(ptr, value);
}, "funtion to test stuff out");
python code
ptr_value = ctypes.c_double()
ptr_addressof = ctypes.addressof(ptr_value)
ptr_object_pointer = pointer(ptr_value)
ptr_pointer = ctypes.cast(ptr_object_pointer, ctypes.c_void_p).value
print(f'python ptr using addressof(ptr_value):\t\t{ptr_addressof}')
print(f'python adress using ctypes.cast:\t\t{ptr_pointer}')
print(f'python ptr object using pointer(ptr_value):\t{ptr_object_pointer}')
value = 14.0
myFunc(ptr_addressof, value)
output
python ptr using addressof(ptr_value): 2784493684616
python adress using ctypes.cast: 2784493684616
python ptr object using pointer(ptr_value): <__main__.LP_c_double object at 0x0000028850C1C8C0>
ptr value: 14
ptr adress: 000000CC2D3EE490
How do I get the same adress in c++ and python?