Log In    |    Knowledge Base    |    4D Home
Tech Tip: Understanding Pointer Dereferencing
Published On: September 28, 2012

4D Pointers are references to 4D objects, variables, tables, fields, etc. A pointer to an object can be used in place of the object itself anywhere in the 4D language. Pointers are invaluable in writing generic routines that can handle different tables and data of different types. This reduces the time and code needed to complete a project and produces code that is more portable.

The key to making effective use pointers is knowing how to properly "dereference" a pointer. Knowing how a pointer was created is the key to knowing how to dereference a pointer. The image below show several scenarios for how pointers are initialized.

Pay close attention to the code on lines 45 and 60 as well as line 53 and 67, 68, and 69. These are examples of pointer referencing other pointers and what is called "double-dereferencing" that has to be done to retrieve the data. Notice the use of parentheses in double-dereferencing. Without the parentheses 4D will through an error

The top of the image displays the data referenced by each pointer.