comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Pointer and structure question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Pointer and structure question [message #81724] Sat, 13 October 2012 19:58
timmyb89 is currently offline  timmyb89
Messages: 4
Registered: October 2012
Junior Member
Thanks, too easy.

On Saturday, October 13, 2012 10:20:36 PM UTC+11, TimB wrote:
> I'm having trouble accessing a structure referred to by a pointer. Here's a simplified example of what I want to do.
>
>
>
> array=replicate(ptr_new(/ALLOCATE_HEAP),2)
>
> *array[0]={var1:1.0,var2:2.0}
>
>
>
> x=*array[0]
>
> print,x.var1
>
> print,*array[0].var1
>
>
>
>
>
> print,x.var1 works, print,*array[0].var1 gives the error "Expression must be a structure in this context: ARRAY.". I need to be able to access var1 without creating the x variable as seen in this example. What am I doing wrong?
>
>
>
> Thanks, Tim
Re: Pointer and structure question [message #81727 is a reply to message #81724] Sat, 13 October 2012 04:30 Go to previous message
Lajos Foldy is currently offline  Lajos Foldy
Messages: 176
Registered: December 2011
Senior Member
On Saturday, October 13, 2012 1:20:36 PM UTC+2, TimB wrote:
> I'm having trouble accessing a structure referred to by a pointer. Here's a simplified example of what I want to do.
>
>
>
> array=replicate(ptr_new(/ALLOCATE_HEAP),2)
>
> *array[0]={var1:1.0,var2:2.0}
>
>
>
> x=*array[0]
>
> print,x.var1
>
> print,*array[0].var1
>
>
>
>
>
> print,x.var1 works, print,*array[0].var1 gives the error "Expression must be a structure in this context: ARRAY.". I need to be able to access var1 without creating the x variable as seen in this example. What am I doing wrong?
>
>
>
> Thanks, Tim

Operator precedence. Use parenthesis when in doubt.

IDL> print,(*array[0]).var1
1.00000

regards,
Lajos
Re: Pointer and structure question [message #81728 is a reply to message #81727] Sat, 13 October 2012 04:28 Go to previous message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 10/13/2012 01:20 PM, TimB wrote:
> print,x.var1 works, print,*array[0].var1 gives the error

print,(*array[0]).var1 should do do it

cheers

Fab
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL 8.2.1 released
Next Topic: Overlay a coloured boundary on a gray scale image

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:43:24 PDT 2025

Total time taken to generate the page: 0.00540 seconds