#: 8700 S3/Languages
12-Dec-90 21:42:10
Sb: #8674-#Dynamic Structure Alloc
Fm: Jay Truesdale 72176,3565
To: Jay Truesdale 72176,3565 (X)
Pete:
Thanks for the confirmation about why I need to worry about what the pointer
points to (pointer math) and why I need to cast the pointer returned by malloc.
I think that I have to do the same cast for the same reasons to do what I
really want to do, reference down the tree. If I want to get the key value
contained in the left node while "at" the root node then
(root_ptr->lp)
references the pointer field in the root node which contains a pointer to the
next node. I want to dereference this to get what this points to (the next
node). The pointer contained in this field is of type b_tree_rec so I need to
cast the de-reference operation to the proper type???
I then can use the -> operator to retrieve the contents to the next node like
this:
((struct b_tree_rec *)(root_ptr->lp))->key
This appears to work as my short test program gets the results I expected. I'm
not sure why I need to cast the de-reference operation as I declared the "lp"
field as being a pointer to type b_tree_rec in the structure template
definition right before main.
Thanks in advance,
-J
There is 1 Reply.
|