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

Home » Public Forums » archive » Storing !NULL in struct
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: Storing !NULL in struct [message #83604 is a reply to message #83531] Mon, 18 March 2013 05:40 Go to previous messageGo to previous message
tom.grydeland is currently offline  tom.grydeland
Messages: 51
Registered: September 2012
Member
On Monday, March 18, 2013 12:20:51 PM UTC, alx wrote:

>> Do you also understand why I referred to this as defeating the purpose of high-level data structures?

> No, I do'nt. I do not understand what you mean by "high-level" data structures.

Basically, LISTs and HASHes. These are capable of storing arbitrary values in each value slot, thereby giving you the opportunity to create arbitrarily complex nested structures. The problem is that values stored in these structures cannot easily be accessed and modified, which defeats the purpose of having these structures in the first place.

> As previously said, IDL structures are defined like C structures: each field being defined "by value". If you want more flexibility, you can (and you must) use pointers (each field is then defined "by reference").

This point has been made several times already, and in my reply to Chris Torrence, I granted that the reasons behind this decision is valid, even if it has a consequence that seems silly by itself.

What I was demonstrating in the message you replied to, however, is a different point. When a struct is stored in a LIST or a HASH, you cannot change its values, while a struct referred to by a pointer _can_ be modified.

Consider this simple example (and before you suggest workarounds, please consider that I already said I understand how to work around these issues, _AND_ that I'm deliberately constructing _simple_ examples, so that the points stand out more clearly, but that the cases I intend to deal with are going to be much more involved, and nested much more deeply than what I'm showing you here):

IDL> .run
- pro modify, s
- s.foo += 1
- end
% Compiled module: MODIFY.
IDL> s = {foo:0}
IDL> modify, s
IDL> help, s
** Structure <23d4ed8>, 1 tags, length=4, data length=4, refs=1:
FOO LONG 1

;; So a structure stored in a simple variable can be MODIFY'ed

IDL> p = ptr_new({foo:0})
IDL> modify, *p
IDL> help, *p
** Structure <23d4b08>, 1 tags, length=4, data length=4, refs=1:
FOO LONG 1

;; Similarly, a structure stored behind a pointer can be MODIFY'ed

IDL> L = list({foo:0})
IDL> help, L[0]
** Structure <23ae368>, 1 tags, length=4, data length=4, refs=2:
FOO LONG 0
IDL> modify, L[0]
IDL> help, L[0]
** Structure <23ae368>, 1 tags, length=4, data length=4, refs=2:
FOO LONG 0

;; while a structure stored in a LIST _cannot_ be MODIFY'ed, and my example fails _without warning_.

Do you see _now_ what I mean by defeating the purpose?

> alx.

--T
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: HASH makes too many temporaries
Next Topic: MGlib IDL library

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

Current Time: Thu Oct 09 21:43:47 PDT 2025

Total time taken to generate the page: 0.24245 seconds