Dereference
In the context of mainframe programming, **dereferencing** is the operation of accessing the data value stored at the memory address indicated by a pointer variable. It effectively "follows" the pointer to retrieve the actual data rather than the memory address itself, enabling indirect access to data. In the context of mainframe programming, particularly in languages like C/C++ and PL/I on z/OS, **dereferencing** is the operation of accessing the value or data stored at the memory address pointed to by a pointer variable. It effectively "follows" the pointer to retrieve the actual data it references, rather than the address itself.
Key Characteristics
-
- Operates on a pointer variable (e.g.,
POINTERin PL/I,*in C) to retrieve the content of the memory location it points to. - Essential for indirect data access, allowing programs to manipulate data whose location is determined at runtime or is not directly named.
- Can lead to program abends (e.g.,
0C4abend,ASRAin CICS) if the pointer contains an invalid or unallocated memory address, or if it's aNULLpointer. - Often used in conjunction with dynamic storage allocation (e.g.,
GETMAINin z/OS Assembler,ALLOCATEin PL/I,mallocin C) where the memory address is returned as a pointer. - In PL/I, dereferencing is often implicit when a
BASEDvariable is associated with aPOINTERvariable, allowing direct access to the data structure defined by theBASEDvariable.
- Operates on a pointer variable (e.g.,
Use Cases
-
- Accessing dynamically allocated storage: After using
GETMAIN(Assembler) orALLOCATE(PL/I) to obtain memory, a pointer to that storage is returned, which must be dereferenced to store or retrieve data within the newly acquired memory block. - Traversing complex data structures: Navigating linked lists, trees, or other structures where elements contain pointers to subsequent elements (e.g., in user-defined control blocks or application-specific data structures).
- Working with system control blocks: In z/OS system programming, pointers are extensively used to locate and access various system control blocks (e.g., TCB, ASCB, DEB) whose addresses are often found in other control blocks or system areas.
- Passing parameters by reference (indirectly): While COBOL typically uses
BY REFERENCE, languages like C or PL/I can pass pointers to data, and the called routine then dereferences these pointers to access and modify the original data in the caller's storage.
- Accessing dynamically allocated storage: After using
Related Concepts
Dereferencing is inextricably linked to pointers, as it is the fundamental operation for using them to access data. It complements memory management concepts like GETMAIN/FREEMAIN (z/OS services) or ALLOCATE/FREE (PL/I) by providing the means to access the storage acquired. In PL/I, it's closely associated with BASED variables, which provide a