Originally posted by: mdiin
I was not talking about define type, but rather using type when referring to a defined structure, like so:
define structure 1 List;
define structure 1 List,
2 head pointer,
2 tail handle List;
declare aList type List;
Talking to one of my colleagues, I think I have figured out what the semantics of the above declare statement is: aList is allocated on the stack and given the amount of memory equal to size(:List:).
When using pointers, and thus also handles, you have to be aware of the difference between the stack and the heap. When creating a new handle using the e.g. new(:List:), heap memory corresponding to the size of List is allocated, and the handle points to this. But when using the handle built-in function to convert aList to a handle(List), the handle points to the location of aList on the stack. The pitfall here is that you cannot return the created handle from a function and still expect to access aList's data - it will be destroyed upon exit from the block in which it was allocated.
So, my conclusion is that handles are to be used when creating recursive data types, and in most other situations one should use declare foo type List.