Next: Adding Children Nodes Up: Creating a New Previous: Overview

Creating the New Tree (Top-Level Node)

The first routine is F_createTree(). F_createTree() It takes one argument, which is a pointer. The routine will create a new node in its memory area, and will make the pointer point at it. The node will have no parent (i.e. it is the top of a new tree). It will initially have no children, but you may add children later. You will never be able to give it a parent; it will always be the top-level node of its tree.

Note that there is something subtle going on here. F_createTree() is able to determine the type of the pointer you pass it. It uses this information to create a node of the proper type. The following program fragment illustrates this. It creates two completely independent trees that are not linked together in any way.


eventNode *evPtr;               // pointer uninitialized; contains garbage
F_createTree(evPtr);            // a new eventNode is created somewhere in
                                // memory and evPtr is changed to point at it
evPtr->run = 2122;              // the event node somewhere in memory is filled

erpNode *erpPtr;
F_createTree(erpPtr);           // this time it is an erpNode that gets created
                                // and erpPtr is changed to point at it
erpPtr->adc0u = 3968;           // the erp node somewhere in memory is filled


walter@
Wed Aug 10 11:53:26 PDT 1994