× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



> From: Scott Klement
> 
> Hi Joe,
> 
> Just curious, but doing it that way, why not use a MODS or an array of
> qualified structures?  Then you wouldn't have to use pointer math to
walk
> through the list.  (Though, you'd still have to use it to set the
start of
> the list.)

Unless I miss my guess, with a MODS or an array of structures, I have to
predefine the number of entries.  I use the technique shown whenever the
size of the structure is known but the number of entries is not; it
allows me to avoid having to specify the maximum number of entries the
API can handle.

If RPG allowed me to pass a pointer to an array of structures and let me
easily determine the size directly from the passed array, I might be
able to do something similar.  Not knowing how to do that, this
technique is a good substitute, working quite nicely when the caller
knows how many entries need to be processed but the callee does not.

I can write the called procedure to handle any arbitrary number of
entries, but the actual number allocated depends on the calling
application.  It's a personal preference based on being bitten one too
many times by fixed array sizes, while at the same time not wanting to
create arrays with an arbitrarily large size.


> I was actually using this with the system "List APIs" however, and the
> size of each entry is not necesarily a fixed number.  (or, even if it
is,
> it can change from release to release, which would break the code the
way
> you've written it)

Well, I did say pretty specifically that the entries need to be a
predefined size based on an external data structure.  I couldn't tell
from your example whether EntrySize was a variable or a constant.

If it were based on a data structure, it would be a pretty simple
recompile for each release.  But if you don't like that, well, do simple
pointer arithmetic: pointer = header + offset + (entry-1) * size.

Or, if your size changes every time, then do this:

   EntrySize = 0;
   Pointer = header + offset;
   For x = 1 to numEntries
     Pointer = Pointer + EntrySize;
     (...)
     EntrySize = SizeOfCurrentEntry;
   Endfor

There are several ways to do it without the nested if logic.  Like I
said, I just showed my little array magic as an example.

Joe


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.