values = ffi.new( "int[]", 10 )
pValue = ffi.addressof( pInt, 0 )
The code above creates a pointer to the first element of values
as pValue
.
You can then access its content with values[ 0 ]
, but this is not really transparent and it is sometimes inconvenient to keep track of what indice is what value.
Is there anything such as the C *-operator
, a function or something else, to dereference pValue
and access its content directly?
In other languages... :
// In C:
// =====
int values[ 10 ] = {0};
int* pValue = &( values[ 0 ] );
func_with_pointer_to_int_as_param( pValue );
printf( "%d\n", *pValue );
-------------------------------------------------------------
# In Python with CFFI:
# ====================
values = ffi.new( "int[]", 10 )
pValue = ffi.addressof( values, 0 )
lib.func_with_pointer_to_int_as_param( pValue ) #lib is where the C functions are
print values[ 0 ] #Something else than that? Sort of "ffi.contentof( pValue )"?
Damien Ruiz