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

Home » Public Forums » archive » Re: Help: Pointer
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: Help: Pointer [message #14865] Sat, 03 April 1999 00:00
steinhh is currently offline  steinhh
Messages: 260
Registered: June 1994
Senior Member
Vu Khac Tri wrote:

> But in C, when c is modified, (*pc) is also modified because
> pc points to the memory where c is. That mean, if c = 5, *pc = 5.

You're right. IDL doesn't have pointers in the same sense
as C does - there is no "address of" operator, and there
is no way to make a pointer that points to a normal variable.

The closest thing (and it's close enough to emulate
the C behaviour, but not it's notation) is:

IDL> c=ptr_new(4)
IDL> pc=c
IDL> print,*pc
4
IDL> *c = 5
IDL> print,*pc
5

I.e., you have two pointers, pointing to the same heap
variable. The only difference from C notation is that
you have to dereference *both* variables as pointers.

Regards,

Stein Vidar
Re: Help: Pointer [message #14885 is a reply to message #14865] Fri, 02 April 1999 00:00 Go to previous message
VU KHAC Tri is currently offline  VU KHAC Tri
Messages: 25
Registered: March 1999
Junior Member
>> In C, I can write:
>>
>> void XXX ()
>> {
>> int C = 4;
>> int *pC;
>> pC = &C; /*pC points to C*/
>> }
>>
>> I cannot find out how to do this in IDL ?
>
> IDL> c = 4
> IDL> pC = Ptr_New(/Allocate_Heap)
> IDL> *pC = c
>

I found this :

IDL> c = 4
IDL> pc = PTR_NEW(/ALLOCATE_HEAP)
IDL> *pc = c
IDL> print, *pc
4
IDL> c = 5
IDL> print, *pc
4

But in C, when c is modified, (*pc) is also modified because pc points
to the memory where c is. That mean, if c = 5, *pc = 5.

Thank you so much for your book.
Best regards,
Tri.
Re: Help: Pointer [message #14890 is a reply to message #14885] Fri, 02 April 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
VU KHAC Tri (tvk@info.fundp.ac.be) writes:

> In C, I can write:
>
> void XXX ()
> {
> int C = 4;
> int *pC;
> pC = &C; /*pC points to C*/
> }
>
> I cannot find out how to do this in IDL ?

IDL> c = 4
IDL> pC = Ptr_New(/Allocate_Heap)
IDL> *pC = c

But most people would just to this:

IDL> pC = Ptr_New(c)

To destroy the pointer (and the thing it points to),
be sure to do this when you are finished:

IDL> Pointer_Free, pC

If you are writing a widget program you can clean up
your pointers in the CLEANUP procedure you assign
to your top-level base with the XMANAGER command.

Cheers,

David

P.S. People may be interested to know that a book is
winging its way to Tri today. :-)

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: "ALOG2" ? (Ugly code follows)
Next Topic: "ALOG2" ?

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

Current Time: Thu Oct 09 06:51:44 PDT 2025

Total time taken to generate the page: 0.72634 seconds