IBM AS/400 Frozen Dessert Maker User Manual


 
Managing Dynamically-Allocated Storage
*-----------------------------------------------------------------*
* *
* After: Now the names name@, name_len and next@ refer *
* to storage in the new element *
* *
* .-------------. .--------------. *
* | | .------>| | *
* | *--->abc | | name * | *
* | 3 | | | name_len | *
* | *----------' | next * | *
*| | | | *
* '-------------' '--------------' *
* *
* Now set the values of the new element. *
* The next pointer is set to *NULL to indicate that it is the *
* end of the list. *
*-----------------------------------------------------------------*
C EVAL next@ = *NULL
*-----------------------------------------------------------------*
* Save the length of the name (not counting trailing blanks)
*-----------------------------------------------------------------*
C EVAL name_len = %len(%trimr(name))
*-----------------------------------------------------------------*
* Storage is allocated for the name and then set to the value of
* the name.
*-----------------------------------------------------------------*
C ALLOC name_len name@
C EVAL %SUBST(nameVal:1&gml.name_len) = name
*-----------------------------------------------------------------*
* *
* After: *
* *
* .-------------. .--------------. *
* | | .------>| | *
* | *--->abc | | name *--->newname *
* | 3 | | | name_len nn | *
* | *----------' | next *--->||| *
*| | | | *
* '-------------' '--------------' *
*-----------------------------------------------------------------*
P AddName E
Figure 52 (Part 3 of 5). Memory Management - Build a Linked List of Names
116 ILE RPG for AS/400 Programmer's Guide