Pointers and arrays are essentially equivalent in c. And pointer arithmatic works like array indexation, so ...

*(snorm+n) = *(snorm+n-1)*(float)(2*n-1)/(float)n;

and

snorm[n] = *(snorm+n-1)*(float)(2*n-1)/(float)n;

and

snorm[n] = snorm[n-1]*(float)(2*n-1)/(float)n;

are all equivalent statements.

A reason you may wish to use the pure pointer form is where you don't want to pass an array and index offset into a function, you can just point to an element. And p++ will increment the pointer to the next array element (probably the reason p is used rather than snorm directly).

Terry


Phil Middlemiss wrote:



I'm converting some code from some ugly C. The code defines one particular array, and a constant like this:

static float snorm[169];
static float *p = snorm;

and then later has an assignment:

*snorm = 1.0;

and then again later (n is an integer iterator):

*(snorm+n) = *(snorm+n-1)*(float)(2*n-1)/(float)n;

The question is this: It looks like the code is simply assigning values to
an array, so why bother with the pointers? Elsewhere the code uses arrays
normally (ie. indexing them with the square brackets) so that makes me think
maybe this is doing something other than just putting values into the array.
Also, I'm assuming that the "p" variable is just a pointer into snorm?

Can anyone make this clear for me?

Cheers,
Phil.

_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi




_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to