Re: [fpc-pascal] Converting code from C++ to FP....

2011-03-19 Thread Aleksa Todorovic
On Sat, Mar 19, 2011 at 06:07, Bo Berglund bo.bergl...@gmail.com wrote:

 1) The second line in the loop contains the command std::max, how can
 that be translated? I have not found any class definition for std
 with a method max


There is function Max in unit Math, so you could say:

jBegin := Max(k-band, 1);

 2) The parameter into the function is a pointer *A of type double. To
 me that indicates a value of some kind, but in the code it suddenly
 seems to appear as an array with indexing. What would be the proper
 pascal translation of this?

Indeed. C doesn't actually have difference between pointer to some
data and arrays. You could use open array:

procedure Decompose(var A: array of double);
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting code from C++ to FP....

2011-03-19 Thread Jeppe Johansen

Den 19-03-2011 08:30, Aleksa Todorovic skrev:



2) The parameter into the function is a pointer *A of type double. To
me that indicates a value of some kind, but in the code it suddenly
seems to appear as an array with indexing. What would be the proper
pascal translation of this?

Indeed. C doesn't actually have difference between pointer to some
data and arrays. You could use open array:

procedure Decompose(var A: array of double);

Or you could use

procedure Decompose(A: pdouble);

That way it would be precisely the same as the C solution. You can 
array-index A the same way as in C(in some fpc modes)

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting code from C++ to FP....

2011-03-19 Thread Ingemar Ragnemalm

Jeppe Johansen jepj...@es.aau.dk wrote:

Den 19-03-2011 08:30, Aleksa Todorovic skrev:
  

2) The parameter into the function is a pointer *A of type double. To
me that indicates a value of some kind, but in the code it suddenly
seems to appear as an array with indexing. What would be the proper
pascal translation of this?
  

Indeed. C doesn't actually have difference between pointer to some
data and arrays. You could use open array:

procedure Decompose(var A: array of double);


Or you could use

procedure Decompose(A: pdouble);

That way it would be precisely the same as the C solution. You can 
array-index A the same way as in C(in some fpc modes)
  


I would only do that when mixing C and Pascal code, to interface with C 
code.
In a Pascal-only program, never. Converting bad C code (that means 
almost any C code)
to good FPC code is a great thing to do, converting to bad FPC code is 
not as much fun.



/Ingemar

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: Converting code from C++ to FP....

2011-03-19 Thread Bo Berglund
On Sat, 19 Mar 2011 08:30:45 +0100, Aleksa Todorovic
alexi...@gmail.com wrote:

On Sat, Mar 19, 2011 at 06:07, Bo Berglund bo.bergl...@gmail.com wrote:

 1) The second line in the loop contains the command std::max, how can
 that be translated? I have not found any class definition for std
 with a method max


There is function Max in unit Math, so you could say:

jBegin := Max(k-band, 1);

 2) The parameter into the function is a pointer *A of type double. To
 me that indicates a value of some kind, but in the code it suddenly
 seems to appear as an array with indexing. What would be the proper
 pascal translation of this?

Indeed. C doesn't actually have difference between pointer to some
data and arrays. You could use open array:

procedure Decompose(var A: array of double);

Thanks for the information!
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. :-(


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting code from C++ to FP....

2011-03-19 Thread Jürgen Hestermann



Ingemar Ragnemalm schrieb:

Converting bad C code (that means almost any C code)
to good FPC code is a great thing to do, converting to bad FPC code is 
not as much fun.
Yes, when already in progress of converting to Pascal then get rid of C 
design flaws and convert to clear Pascal code.




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Converting code from C++ to FP....

2011-03-19 Thread Aleksa Todorovic
On Sat, Mar 19, 2011 at 13:03, Bo Berglund bo.bergl...@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);
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] double dispatch

2011-03-19 Thread Jonas Maebe

On 18 Mar 2011, at 22:47, Jorge Aldo G. de F. Junior wrote:

 Can FPC deal with double-dispatch ?

No, because overloading works the same as in C++ (determined statically at 
compile time).


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: Converting code from C++ to FP....

2011-03-19 Thread Bo Berglund
On Sat, 19 Mar 2011 13:10:25 +0100, Jürgen Hestermann
juergen.hesterm...@gmx.de wrote:



Ingemar Ragnemalm schrieb:
 Converting bad C code (that means almost any C code)
 to good FPC code is a great thing to do, converting to bad FPC code is 
 not as much fun.
Yes, when already in progress of converting to Pascal then get rid of C 
design flaws and convert to clear Pascal code.


That is indeed my aim! :-)


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Converting code from C++ to FP....

2011-03-19 Thread Jorge Aldo G. de F. Junior
no one explained so let me try :

 void ForwardModel::SetMixedBoundaryCondition(const int iElec,

void somefunction means its a pascal procedure

   const double* SX0,

const has the same effect as fpc const before a parameter,

double* SX0
is the same as
double *SX0
or
double * SX0

so this becomes

const SX0 : pdouble (ugly pointer as array Cishism)

   const double* SY0,

const SY0 : pdouble

   const double* SZ0,

idem

   double* SX,
   double* SY,
   double* SZ)

SX : pdouble;

etc
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: double dispatch

2011-03-19 Thread leledumbo
 No, because overloading works the same as in C++ (determined statically at
compile time).

Are you sure, Jonas? Because I've been able to implement visitor pattern
which is a kind of double dispatch. Of course it's not implemented like the
example posted by the OP, but more like a simulation explained in 
http://en.wikipedia.org/wiki/Double_dispatch wikipedia .

--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/double-dispatch-tp3987828p4072095.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: double dispatch

2011-03-19 Thread Jonas Maebe

On 19 Mar 2011, at 15:58, leledumbo wrote:

 No, because overloading works the same as in C++ (determined statically at
 compile time).
 
 Are you sure, Jonas?

Yes.

 Because I've been able to implement visitor pattern
 which is a kind of double dispatch. Of course it's not implemented like the
 example posted by the OP, but more like a simulation explained in 
 http://en.wikipedia.org/wiki/Double_dispatch wikipedia .

Exactly, it's an emulation: achieves the same effect without availability of 
double dispatch.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: double dispatch

2011-03-19 Thread Marco van de Voort
In our previous episode, leledumbo said:
  No, because overloading works the same as in C++ (determined statically at
 compile time).
 
 Are you sure, Jonas? Because I've been able to implement visitor pattern
 which is a kind of double dispatch. Of course it's not implemented like the
 example posted by the OP, but more like a simulation explained in 
 http://en.wikipedia.org/wiki/Double_dispatch wikipedia .

That is purely statically typed based overloading as far as I can see, and
doesn't switch methods at runtime.

The only escape that I know to statically typed calling in FPC is IDispatch.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: Converting code from C++ to FP....

2011-03-19 Thread Bo Berglund
On Sat, 19 Mar 2011 11:30:47 -0300, Jorge Aldo G. de F. Junior
jagf...@gmail.com wrote:

no one explained so let me try :

 void ForwardModel::SetMixedBoundaryCondition(const int iElec,

void somefunction means its a pascal procedure

   const double* SX0,

const has the same effect as fpc const before a parameter,

double* SX0
is the same as
double *SX0
or
double * SX0

so this becomes

const SX0 : pdouble (ugly pointer as array Cishism)

   const double* SY0,

const SY0 : pdouble

   const double* SZ0,

idem

   double* SX,
   double* SY,
   double* SZ)

SX : pdouble;

etc

Thanks! :-)


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal