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

Home » Public Forums » archive » Re: Problem of precedence with pointer and structure
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Problem of precedence with pointer and structure [message #47150] Fri, 27 January 2006 12:22 Go to previous message
L. Testut is currently offline  L. Testut
Messages: 16
Registered: January 2006
Junior Member
a=ptrarr(5,/allocate_heap)
IDL> help,a
A POINTER = Array[5]
; A is an array of pointer OK


IDL> help,a[0]
<Expression> POINTER = <PtrHeapVar1>

; a[0] is a scalar pointer OK


IDL> help,/heap
Heap Variables:
# Pointer: 5
# Object : 0
<PtrHeapVar1> UNDEFINED = <Undefined>
<PtrHeapVar2> UNDEFINED = <Undefined>
<PtrHeapVar3> UNDEFINED = <Undefined>
<PtrHeapVar4> UNDEFINED = <Undefined>
<PtrHeapVar5> UNDEFINED = <Undefined>

; I've defined 5 differents scalar pointers (included in an array)
pointing on 5 differents heap variable
; I can affect to each of them the heap variable I want
IDL> *a[0]=0.
IDL> *a[1]='I hate pointers'
IDL> *a[2]=indgen(10)
IDL> *a[3]='ok ok we have understoodd !!'
IDL> *a[4]=4.
IDL> for i=0,4 do print,*a[i]
0.00000
I hate pointers
0 1 2 3 4 5 6 7
8 9
ok ok we understand !!
4.00000

; Now if I want to have an array of structure with a field b which is a
pointer

IDL> a=replicate({b:ptr_new(/allocate_heap)},5)
IDL> help,a
A STRUCT = -> <Anonymous> Array[5]
IDL> help,a.b
<Expression> POINTER = Array[5]

; So i think that (a.b) is equivalent to my previous a (e.g an array of
pointer pointing a 5 differents heap variable
; but as i *replicate* my structure I have 5 identical pointer variable
pointing to only ONE heap variable !!!
IDL> *(a[0].b)=0.0
IDL> *(a[1].b)='I hate pointers'
IDL> *(a[2].b)=indgen(10)
IDL> *(a[3].b)='ok ok we have understood !!'
IDL> *(a[4].b)=4.
IDL> for i=0,4 do print,*a[i].b
4.00000
4.00000
4.00000
4.00000
4.00000

; Then can you confirm me that it is stupid to replicate a structure
with a pointer variable field
; or that I am stupid to think that !

> P.S. If I'm not mistaken, I think I recommended that structure
> solution. :-)

Yes you did :-)

Thanks,
Laurent
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Problem of precedence with pointer and structure
Next Topic: Re: Extract a sub-structure from a structure

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

Current Time: Thu Oct 09 20:38:11 PDT 2025

Total time taken to generate the page: 0.24463 seconds