Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert pascal to C

Ivan_118
Occasional Contributor

Convert pascal to C

I need to convert some legacy pascal program to C on my Alpha, somehow I didn't get this right. What is wrong with my C code? Any ideas?

Thanks in advance.
-Ivan

=======================================

(* convert this pascal code to C *)

_UQUAD = [QUAD,UNSAFE] PACKED RECORD
L0,
L1 : UNSIGNED;
END;

Tel = [aligned] PACKED RECORD
X0 : [BIT(3)] 0..7;
X1 : _UQUAD;
X2 : BOOLEAN;
X3 : ARRAY [1..16] OF _UQUAD;
X4 : ARRAY [1..16] OF BOOLEAN;
END;

======================================
// This is my C code

struct tel {
unsigned X0 : 3;
uint64 X1;
uint64 X2;
bool X3;
uint64 X4[16];
bool X5[16];
};
2 REPLIES
Hein van den Heuvel
Honored Contributor

Re: Convert pascal to C

Well, I don't pretend to remember the PASCAL allignment rules vs C rules, but what you show has simple miscounts/mislabels.

Should the C not be:

struct tel {
unsigned X0 : 3;
uint64 X1;
bool X2;
uint64 X3[16];
bool X4[16];
};

Now what does that 'bool' map to through your includes? Is every bool becoming an int thus taking 64 bytes? The array of boolean in Pascal is probably a bit-array taking 2 bytes.

Be sure to write a trivial test program allocating this structure in both languages and compile with full listing showing the variable allocations.

Is the structure just use in runtime by a single language, or exchanged between languages, or stored on disk where you need to use an old file? For the first case you can just pick your favourite C constructs. For the other you'll need to control aligment down to the bit.

Hope this helps a little,
Hein.
Brian Reiter
Valued Contributor

Re: Convert pascal to C

What is the problem you're hitting?

From the Pascal I got a size of 202 bytes (layout attached). The array of BOOLEAN is 64 bytes so its going to be confusing to map. At a guess I would go:

X0 char
X1 uint64
X2 byte
X3 uint64[16]
X4 uint[16]

No idea where you've got the additional field from (unless I've missed something obvious).