You need to know exactly what the invoked C++ function is expecting.
In C (and C++) all of these function signatures are for all intents and purposes exactly the same:
void foo( float *x , float *y ) ;
void foo( float *x , float y[] ) ;
void foo( float x[] , float *y ) ;
void foo( float x[] , float y[] ) ;
All of them take 2 arguments, each of which contains is a pointer to (contains the address of) a variable of type float
. And all of these expressions are exactly identical in C/C++:
float x[] ;
float *y ;
float r1 = *(x+37) ; // all evaluate to the zero-relative
float r2 = x[37] ; // 37th element of the array.
float r3 = *(y+37) ;
float r4 = y[37] ;
- The expression
*x
says, "Fetch the float
(4 bytes) located at the address contained in x
.
- The expression
*(x+n)
, where n
is an integer value, says "Take the address contained in x, and to that add the offset in bytes obtained by the expression sizeof(float) * n
. Fetch the float
value located at the resulting address.
- The array expression
x[n]
is exactly equivalent to the pointer expression *(x+n)
.
And since arrays in C/C++ do not have any associated metadata describing their size, you need to know exactly what the called function is expecting.
Commonly, one passes a pointer (call by reference) in order to allow the caller to de-reference the point and set a value for you — the equivalent of C#'s ref
and out
keywords:
float x ;
float y ;
Foo( ref x , ref y ) ; // the callee MAY, but is not REQUIRED to set a value before returning to the caller.
Bar( out x , out y ) ; // the callee MUST set a value before returning to the caller.
The idiom your function is using is always used to locate an array, though typically, one also passes a size:
void foo( float *array , int array_length ) ;
Although is it not unusual, if the function is expecting the array to be a list of non-zero numeric values to be something like a C-style, NUL-terminated string. Given the function signature, for instance:
float compute_mean( float *Xs ) ;
It's not unusual for it to be expected to be invoked thus:
float Xs[] = { 3.0 , 2.5 , 9.8 , 7,5 , 0 , } ;
float mean = compute_mean( Xs ) ;
and the definition to be something like:
float compute_mean( float *Xs )
{
float n = 0.0 ;
float sum = 0.0 ;
float mean ;
while ( *p )
{
++n ;
sum += *p++ ;
}
mean = n > 0 ? sum / n : 0.0 ;
return mean ;
}
So you need to know the semantics of the method you're invoking.
Hope this helps.