//-------------------------------------------------------------------------- // Many forms of allocate; variables, array, structures; with size, high //------------------------------------------------------------------------- main module ALLOCATEX use TEXTIO // Allocation of an array with an initial condition declare X_type is packed array [1..9] of char X_pointer is pointer X_Type P_X : X_Pointer P_X_Blank : X_Pointer enddeclare P_X := allocate X_pointer ("ALLOCATEX" ) P_X_Blank := allocate X_Pointer () P_X_Blank@ := ".PRX " out_string (TTY, P_X@) out_string (TTY, P_X_Blank@) out_record (TTY) // test allocation with initial conditions through a pointer declare Init_Type is integer initially 77 Init_pointer is pointer Init_Type Init : Init_Pointer Final : Init_Pointer Init_val : Init_Type enddeclare Init := allocate Init_Pointer (Init_Val) Final := allocate Init_Pointer (Init@) out_integer (TTY, Final@, "Correct Initial condition = 77 :") out_record (TTY) // Allocate initialized flexible arrays declare Flex_array is packed array [1..?MM] of char P_Flex is pointer Flex_array Top1 : static P_Flex Top2 : P_Flex Top3 : P_Flex I_Count : static integer initially 4 enddeclare Top1 := allocate P_Flex ("ABCDE") // allocate non-initialized flexible array of fixed size Top2 := allocate P_Flex (8) // Assign string to array Top2@ := "12345678" // allocate non_initialized flex array of variable size Top3 := allocate P_Flex (MM:I_Count) Top3@ := " WHY" out_string (TTY, top1@) out_string (TTY, top2@) out_string (TTY, top3@) out_record (TTY) // Note that an "allocate P_Flex (I_Count)" syntax is accepted by the // compiler and some older software is written with it in the compiler. // It is shown here, but it is to be discouraged in the future. Free (Top3) Top3 := allocate P_Flex (I_Count) Top3@ := " WHY" out_string (TTY, top1@) out_string (TTY, top2@) out_string (TTY, top3@) out_record (TTY) // high and size of flexible array out_integer (TTY, High (Top1@), "High of string = ") out_record (TTY) out_integer (TTY, integer(sizeof (Top1@)), "Sizeof string = ") out_record (TTY) Free (Top1) Free (Top2) // Test allocation of a structure with initial conditions declare A is structure B : integer endstructure Pointer_To_A is pointer A P : pointer_to_A enddeclare P := allocate Pointer_to_A (B : 40) out_integer (TTY, P@.B, "Initial value of structure = ") out_record (TTY) endmodule