9434
Accessing structure fields using IDL pointers
If you define a structure and have created a pointer to that structure, how do you access the individual tags of the structure through the pointer? Currently when you try to access the tags of that structure, you get an error similar to this:
% Expression must be a structure in this context: SPTR.
Suppose a structure, s, was created and a pointer to that structure, sptr, was also created. For example:
IDL> s = {name: 'Joe', age:40, height: 69.3}
IDL> sptr =PTR_NEW(s)
To access the fields of the structure s by using sptr, sptr must first be dereferenced, then the field(s) can be extracted:
IDL> PRINT, (*sptr).name, (*sptr).age
If an attempt was made to extract the field name using the statement *sptr.name, without the parenthesis, IDL would think that sptr is a structure that contains a pointer. The variable sptr is a pointer that contains a structure, not a structure that contains a pointer.