A
almurph
Folks,
Hope you can help me here. I know this is the C# forum but I have
translated some C into C# and I'm wondering did I get it right? So, I
would appreciate any corrections/comments/suggestions that you may be
able to make (or even a way of doing this equivalently without
pointers). I hate working with pointers ;-(
Anyway below is the C original code and my attempt on it below that.
It should be noted that weight is an array of type double.
Thanks again for any corrections/comments.
Al
**** C Language Code As Follows *****
int A, B;
int *Wb, *Wa;
double Sum=0.0;
for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
{
Sum += *Wb++;
}
return Sum;
**** END C CODE ****
Here is my C#.NET attempt:
**** BEGIN MY C# ATTEMPT ****
int B, A;
double sum = 0.0;
unsafe
{
fixed (double* start = &Weight)
fixed (double* end = &Weight[A])
{
for (double* Wb = start; Wb <= end; Wb++)
{
Sum += *Wb++;
}
}
}
return Sum;
**** END C# ATTEMPT *****
Hope you can help me here. I know this is the C# forum but I have
translated some C into C# and I'm wondering did I get it right? So, I
would appreciate any corrections/comments/suggestions that you may be
able to make (or even a way of doing this equivalently without
pointers). I hate working with pointers ;-(
Anyway below is the C original code and my attempt on it below that.
It should be noted that weight is an array of type double.
Thanks again for any corrections/comments.
Al
**** C Language Code As Follows *****
int A, B;
int *Wb, *Wa;
double Sum=0.0;
for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
{
Sum += *Wb++;
}
return Sum;
**** END C CODE ****
Here is my C#.NET attempt:
**** BEGIN MY C# ATTEMPT ****
int B, A;
double sum = 0.0;
unsafe
{
fixed (double* start = &Weight)
fixed (double* end = &Weight[A])
{
for (double* Wb = start; Wb <= end; Wb++)
{
Sum += *Wb++;
}
}
}
return Sum;
**** END C# ATTEMPT *****