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

Home » Public Forums » archive » Re: Newbie Questions
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: Newbie Questions [message #25036] Tue, 15 May 2001 12:21 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Geoff Herbynchuk <gherbyn@irus.rri.on.ca> writes:

> Hi,
>
> Was just wondering if IDL can have pointers to structures. I'm trying to
> access a variable in the structure with:
>
> if (*info).active_cursor EQ 1) then .....
>
> And I keep getting an error which says "Expression must be a structure in
> this context: <PtrHeapVar57>."
>
> Does anyone know what I'm doing wrong?

Umm, are you sure that INFO points to a structure? I tried it and it
worked fine. (see below). Why not put a "HELP, *INFO, /STRUCT" right
before this statement and see what pops up?

IDL> struct = {active_cursor: 1}
IDL> info = ptr_new(struct)
IDL> help, (*info).active_cursor
<Expression> INT = 1
IDL> help, info
INFO POINTER = <PtrHeapVar1>

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Newbie Questions [message #25037 is a reply to message #25036] Tue, 15 May 2001 11:51 Go to previous messageGo to next message
Ben Tupper is currently offline  Ben Tupper
Messages: 186
Registered: August 1999
Senior Member
Geoff Herbynchuk wrote:

> On Tue, 15 May 2001, Geoff Herbynchuk wrote:
>
>> Was just wondering if IDL can have pointers to structures. I'm trying to
>> access a variable in the structure with:
>>
>> if (*info).active_cursor EQ 1) then .....
>>
>> And I keep getting an error which says "Expression must be a structure in
>> this context: <PtrHeapVar57>."
>>
>

Hello,

If the active_cursor tag represents the pointer within the structure, then you
will want to dereference it as follows:

if *(info.active_cursor) EQ 1 then .....

As JD has pointed out to the us pointer-challenged, you can also go the lazy
route:

if *info.active_cursor EQ 1 then .....

The way you have written (*info).active_cursor indicates that info is a pointer
to a structre that conatins the active_cursor rather than being a structure
containing a field defined as pointer.

Ben


--
Ben Tupper
248 Lower Round Pond Road
POB 106
Bristol, ME 04539

Tel: (207) 563-1048
Email: PemaquidRiver@tidewater.net
Re: Newbie Questions [message #25038 is a reply to message #25037] Tue, 15 May 2001 10:17 Go to previous messageGo to next message
Geoff Herbynchuk is currently offline  Geoff Herbynchuk
Messages: 6
Registered: May 2001
Junior Member
On Tue, 15 May 2001, Geoff Herbynchuk wrote:

> Hi,
>
> Was just wondering if IDL can have pointers to structures. I'm trying to
> access a variable in the structure with:
>
> if (*info).active_cursor EQ 1) then .....
>
> And I keep getting an error which says "Expression must be a structure in
> this context: <PtrHeapVar57>."
>
> Does anyone know what I'm doing wrong?
>
> Thanks,
> Geoff Herbynchuk
>
Oh, oops...in the actual code, the brackets do match up correctly
for that "if" statement when I get this error. I just made a typo
when writing this message.
Re: Newbie Questions [message #25109 is a reply to message #25036] Thu, 17 May 2001 05:15 Go to previous message
Geoff Herbynchuk is currently offline  Geoff Herbynchuk
Messages: 6
Registered: May 2001
Junior Member
Thanks for the help guys, got that problem fixed. I'm hoping you can help
me with one more thing with IDL pointers.
When we do something like:

foo_ptr = ptr_new(foo)

foo_ptr points to a memory location in the heap memory that contains
foo's value, correct? So, am I safe to assume it copys whatever the value of
foo is into the heap variable that foo_ptr is pointing too?
And, if we do:

bar_ptr = ptr_new(bar, /no_copy)

bar_ptr will now just point to the memory location where bar is stored
(not copy it to a heap location)? We can then update the bar, or the
components of bar(if bar is a structure) by dereferencing bar_ptr, right?
For example:

*bar_ptr.name = 'Geoff'

Thanks for everyone's help. I've only worked with pointers in
C/C++ before, and I'm getting the impression that these don't work exactly
the same way. =)

Geoff Herbynchuk
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL sockets
Next Topic: Re: WTD: Orbital analysis with IDL

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

Current Time: Wed Oct 08 13:47:11 PDT 2025

Total time taken to generate the page: 0.00650 seconds