[fpc-pascal] Re: Converting code from C++ to FP....
Aleksa Todorovic
alexione at gmail.com
Sat Mar 19 13:33:27 CET 2011
On Sat, Mar 19, 2011 at 13:03, Bo Berglund <bo.berglund at gmail.com> wrote:
>
> Now I have found another very strange construct:
>
> void ForwardModel::SetMixedBoundaryCondition(const int iElec,
> const double* SX0,
> const double* SY0,
> const double* SZ0,
> double* SX,
> double* SY,
> double* SZ)
>
> Now it seems like the variable type declaration itself is a
> pointer....
>
> Instead of double *Name it is double* Name. What is the difference?
> It is still being used as an array:
> SX[n1] = SX0[n1] * (1.0 - w1);
>
> Does C++ allow any placement of the * operator with the same meaning?
>
> And what does const double* mean? Pointer to some object but not
> allowed to change that object????
>
> Having programmed Delphi for 16 years this is hard to wrap ones head
> around. :-(
Welcome to the world of Chell ;-) I (unfortunately) have to use it
daily. Ok, not let's be helpful.
In the situation above, const has similar meaning as the one in Pascal
- you have some value which you are not allowed to change. So, your
header should be something like:
procedure ForwardModel.SetMixedBoundaryCondition(const iElec :
Integer; const SX0, SY0, SZ0 : array of double; var SX, SY, SZ : array
of double);
Hint: if you use trunk version of FPC, I suggest you use constref to
ensure SX0, SY0 and SZ0 are passed as pointer.
procedure ForwardModel.SetMixedBoundaryCondition(const iElec :
Integer; constref SX0, SY0, SZ0 : array of double; var SX, SY, SZ :
array of double);
As Jeppe suggested, you can also use pointers:
procedure ForwardModel.SetMixedBoundaryCondition(const iElec :
Integer; const SX0, SY0, SZ0 : pdouble; SX, SY, SZ : pdouble);
More information about the fpc-pascal
mailing list