I have searched the mailing list archive and have not found the information that I needed. I hope somebody here can provide the answers or point me to where I can find them.
I am porting existing code from a RISC/SunOS system to an Intel(PC)/Solaris7 system. I am using gpc version 20010623, based on gcc-2.95.2 19991024 (release).
In the program below, GPC and the RISC/SunOS compiler do not produce the same results in the NEW call: New(point3, No). GPC will allocate the total size (168 bytes) of the record (ItemData) and will initialize the field 'tag' to 1 (which is NO in the enumeration type Answer). In the SunOS compiler, this same statement will allocate memory (92 bytes) to accomodate the following fields for ItemData: number, tag, A_string, False_entries) and will NOT initialize the tag field.
How do I get GPC to compile the NEW call in the same way as the SunOS Pascal compiler? BTW, the Dispose call in SunOS Pascal passes both pointer and size (based on the second parameter to the dispose call) to the Dispose routine.
program AlignOfDemo;
Type Item_ptr = ^ItemData; Answer = (Yes, No, DontKnow, whatever); ItemData = Record number : Integer; Case tag : Answer of
Yes : (RealData : Array [1..10] of Real; Num_entries : Integer); No : (A_String : Array [1..80] of char; False_entries : Integer); Whatever, DontKnow: (DontCare : Array [1..40] of Integer); End;
var a: Integer; b: array [1 .. 8] of Char; c: Integer (12); d: packed record x: Integer (12); y: 0 .. 3; z: Integer end; point1, point2, point3 : Item_ptr;
begin New(point1); New(point2, Whatever); (* Make sure to use same tag as in dispose *) New(Point3, No); (* Make sure to use same tag as in dispose *) Dispose (point1); Dispose(point2, Whatever); (* Make sure to use same tag as in NEW *) Dispose(Point3, No); (* Make sure to use same tag as in NEW *)
WriteLn (AlignOf (a)); { Alignment of `Integer'; usually 4 bytes. } WriteLn (AlignOf (Integer)); { The same. } WriteLn (AlignOf (b)); { Alignment of `Char'; usually 1 byte. } Writeln (AlignOf (c)); Writeln ('AlingOf d is ', AlignOf (d)); { Alignment of 1 if packed record; 4 if record} { The following 3 statements cannot be compiled by AlignOf (cannot handle bit fields) if used with PACKED RECORD. Writeln ('d.x: Integer (12) is ', AlignOf (d.x)); (*Alginment of 2*) Writeln ('d.y: 1 ..3 is ', AlignOf (d.y)); (*Alginment of 4*) Writeln ('d.z: Integer is ', AlignOf (d.z)); (*alignment of 4*) {} Writeln('that''s all folks!!!') end.
Here is the GPC compiled code for New(point3,NO) 108 0040 83C4F4 addl $-12,%esp 109 0043 68A80000 pushl $168 <<<<<<size to be allocated...... 109 00 110 0048 E8FCFFFF call _p_new 110 FF 111 004d 83C410 addl $16,%esp 112 0050 89C0 movl %eax,%eax 113 0052 A31C0000 movl %eax,Point3 113 00 114 0057 A11C0000 movl Point3,%eax 114 00 115 005c C7400401 movl $1,4(%eax) <<<initializes tag field.... 115 000000 34:align_demo.p **** New(Point3, No); (* Make sure to use same tag as in dispose *)
and the correspoding SunOS Pascal translation: ! New(Point3, No); (* Make sure to use same tag as in dispose *) set _point3,%o0 mov 0x5c,%o1 <<<<<size to be allocated.......... call _NEW,2 nop
The SunOS dispose call is translated as: ! Dispose(Point3, No); (* Make sure to use same tag as in NEW *) set _point3,%o0 mov 0x5c,%o1 call _DISPOSE,2 nop
Thanks in advance for any inputs and suggestions.
Regards,
Jing Gloria Texas Instruments Sherman, Tx
__________________________________________________ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com