[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*Subject*: Re: accessing heap variable elements*From*: Ken Mankoff <mankoff(at)lasp.colorado.edu>*Date*: Sat, 12 May 2001 11:42:56 -0600*In-Reply-To*: <Pine.LNX.4.33.0105121127170.1969-100000@sands.stuff.org>*Newsgroups*: comp.lang.idl-pvwave*Organization*: University of Colorado, Boulder*References*: <3AFD697D.6B597424@nmt.edu> <Pine.LNX.4.33.0105121127170.1969-100000@sands.stuff.org>*Reply-To*: Ken Mankoff <mankoff(at)lasp.colorado.edu>*Xref*: news.doit.wisc.edu comp.lang.idl-pvwave:24910

On Sat, 12 May 2001, Ken Mankoff wrote: > On Sat, 12 May 2001, Jared Crossley wrote: > > > Can any one explain this to me? > > ------------------------------------ > > IDL> a=ptr_new( lonarr(2) ) > > IDL> help, a > > A POINTER = <PtrHeapVar2229> > > IDL> help, *a > > <PtrHeapVar2229> > > LONG = Array[2] > > IDL> help, *a[0] > > <PtrHeapVar2229> > > LONG = Array[2] > > IDL> help, *a[1] > > % Attempt to subscript A with <INT ( 1)> is out of range. > > ------------------------------------ > > I would expect that *a[0] and *a[1] would be long integers. How do I > > access the elements in the long integer array heap variable? > > > > Thanks, Jared > > Hi Jared, > > last line should be (*a)[0] > > -k. > sorry, i realized i should include an explanation, as you requested. its all about operator precedence. Now, "[" is *not* mentioned in the IDL 5.3 Online Help, but they have this: Priority Operator ---------------------------------------------------------------------- First (highest) ( ) (parentheses, to group expressions) Second * (pointer dereference) ^ (exponentiation) Third * (multiplication) # and ## (matrix multiplication) etc. I think its safe to assume that [ ] is parsed as ( ). so: ( *a[ 0 ] EQ *(a[ 0 ]) ) which means "take subscript of 'a', then dereference it." But 'a' is a pointer to an array, not an array of pointers. So you can't subscript it, and even if you could, i'm not sure what you'd be dereferenceing with your *. You want the opposite order, or: (*a)[ 0 ] which means "dereference 'a', then take subscript." -k. -- Ken Mankoff LASP://303.492.3264 http://lasp.colorado.edu/~mankoff/

**References**:**accessing heap variable elements***From:*Jared Crossley

**Re: accessing heap variable elements***From:*Ken Mankoff

- Prev by Date:
**Re: accessing heap variable elements** - Next by Date:
**Convert Integer to Text** - Prev by thread:
**Re: accessing heap variable elements** - Next by thread:
**Convert Integer to Text** - Index(es):