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

Ingemar Ragnemalm ingemar at ragnemalm.se
Sat Mar 19 12:34:32 CET 2011


Jeppe Johansen <jepjoh2 at 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




More information about the fpc-pascal mailing list