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

Home » Public Forums » archive » confusion around a pointer to an array of structures
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
confusion around a pointer to an array of structures [message #45001] Tue, 09 August 2005 11:42 Go to previous message
Henry is currently offline  Henry
Messages: 8
Registered: April 2005
Junior Member
I've been beating my head on this and can't find anything on David's
web site or here that answers my problem. (Which is usually a sign to
me that I am trying to do something really
wrong/inefficiently/stupidly, and yet in this instance I persist.)

For reasons that aren't important to my question, I want to have a
pointer to an array of structures. I've stripped the problem down to
the bare essentials here. (Which was the first thing I did to try to
make sure I wasn't making some other larger error.) Making this ptr is
no problem. Reading the variables is no problem. It's writing to the
variables I'm having a problem with. The best explanation of my
problem is a few lines of code:

;set up our crazily designed ptr to an array of structures
a = ptr_new( replicate( {x:0d}, 5 ) )
;we *can* set the whole variable at once, e.g.:
(*a).x = dindgen(5)
print,(*a).x ; print everything
print,((*a)[0]).x ; print just the first element
;that's all good, but what if you want to set just the first element
equal to something?
((*a)[0]).x = 99d
;this gives the error: % Attempt to store into an expression:
Structure reference.

One way around this is to do something dumb, like:
temp = (*a).x
temp[0] = 99d
(*a).x = temp

But, I can see no other way around this, aside from redesigning how I'm
storing the information. Does anyone see how to do the equivalent of
"((*a)[0]).x = 99d" in the above example? (without the awkward three
line dumb hack I've shown)
I'm sure I'm just not seeing something simple....

Thanks!
-Henry
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: confusion around a pointer to an array of structures
Next Topic: Source for reverse_indices

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

Current Time: Wed Oct 08 16:56:40 PDT 2025

Total time taken to generate the page: 0.00359 seconds