There are a number of programs that do translation from C to Pascal: http://c2pas.sourceforge.net/ http://www.synaptics.com/people/daveg/
and from Pascal to C http://www.rocketaware.com/spec/softdev/lang/pascal/
I have not tried these out - just found them on Google. It might be worth giving them a try with some short bits of code.
Best regards, Chris.
On 7 Jan 2006 at 10:41, Chris Hicks wrote:
There are a number of programs that do translation from C to Pascal: http://c2pas.sourceforge.net/ http://www.synaptics.com/people/daveg/
and from Pascal to C http://www.rocketaware.com/spec/softdev/lang/pascal/
I have not tried these out - just found them on Google. It might be worth giving them a try with some short bits of code.
Thanks. I was aware of those kinds of tools, but not of the sourceforge project (seems dead now). Trying it on the code produced something less useful than I could translate myself!
Actually, the only part of the code I am not sure of is this: for(; length; length >>= 8) crc =(crc << 8) ^ crctab[((crc >> 24) ^ length) & 0xFF];
Which I have half-translated into this: for (; length; length + (length shr 8)) do crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF];
As you can see, I don't understand the for-loop ...
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Hi,
On Sat, Jan 07, 2006 at 12:12:05PM -0000, Prof A Olowofoyeku (The African Chief) wrote:
Which I have half-translated into this: for (; length; length + (length shr 8)) do crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF];
As you can see, I don't understand the for-loop ...
for() loops in C are actually best translated into while loops first:
for( start; condition; increment ) { block; }
translates to:
start; while( condition ) { block; increment; }
so in this case, the C statement
for(; length; length >>= 8) crc =(crc << 8) ^ crctab[((crc >> 24) ^ length) & 0xFF];
can be translated to:
/* no loop initialization */ while( length != 0 ) { crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF]; length := length shr 8; }
("variable >>= bits" is the same as "variable = variable >> bits")
My pascal is too rusty to get the syntax for the actual "while" loop right, but I think with the C explanations, you should be able to translate the rest :-)
gert
On 7 Jan 2006 at 13:51, Gert Doering wrote:
Hi,
On Sat, Jan 07, 2006 at 12:12:05PM -0000, Prof A Olowofoyeku (The African Chief) wrote: > Which I have half-translated into this: > for (; length; length + (length shr 8)) do > crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF]; > > As you can see, I don't understand the for-loop ...
for() loops in C are actually best translated into while loops first:
for( start; condition; increment ) { block; }
translates to:
start; while( condition ) { block; increment; }
so in this case, the C statement
for(; length; length >>= 8) crc =(crc << 8) ^ crctab[((crc >> 24) ^ length) & 0xFF];
can be translated to:
/* no loop initialization */ while( length != 0 ) { crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF]; length := length shr 8; }
("variable >>= bits" is the same as "variable = variable >> bits")
Many thanks. This was the information and confirmation that I needed.
I had alread translated it to: While (length > 0) do begin crc := (crc shl 8) XOR crctab[((crc shr 24) XOR length) AND $FF]; length := length shr 8; end;
but I was not sure what I was doing!
From what you say, it would seem that this is more correct for the loop
condition (if "length" is signed): While (length <> 0) ...
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Hi,
On Sat, Jan 07, 2006 at 01:05:02PM -0000, Prof A Olowofoyeku (The African Chief) wrote:
From what you say, it would seem that this is more correct for the loop condition (if "length" is signed): While (length <> 0) ...
Well, in C, "while (length)" will just test for "anything that is not 0", so yes, "length <> 0" would reflect this better.
As far as I can see, length should never become negative in this code, so this point is probably moot here :)
gert
On 7 Jan 2006 at 15:15, Gert Doering wrote:
Hi,
On Sat, Jan 07, 2006 at 01:05:02PM -0000, Prof A Olowofoyeku (The African Chief) wrote: > From what you say, it would seem that this is more correct for the loop > condition (if "length" is signed): > While (length <> 0) ...
Well, in C, "while (length)" will just test for "anything that is not 0", so yes, "length <> 0" would reflect this better.
As far as I can see, length should never become negative in this code, so this point is probably moot here :)
Ok, thanks ...
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/