Jing Gloria wrote:
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.
I'm afraid this is not possible in GPC yet.
From the GPC manual -> To Do -> Planned Features -> Records/arrays:
* when applying `New' to a variant record type with a selector given, only allocate the space necessary for the selected variant (varrec2.pas) ???
However, you may use `GetMem (Point3, 92)' (this is problematic if some of the record fields require initialization, e.g. strings, schemata, objects).
BTW, the compiler never needs to pass the size to Dispose, because the memory management system (libc: malloc, free) knows by itself what was allocated to the pointer.
Emil Jerabek