|
Hi James, What you said sounds right to me. If you simply want to use pointers, forget the DIM or OCCURS and just user pointer arithmetic and be sure you don't lose track of what you're trying to access vs what you allocated memory for. My only suggestion would be to comment thoroughly enough for the next programmer who may not be up on pointers and could go off into left field. Peter Dow Dow Software Services, Inc. 909 425-0194 voice 909 425-0196 fax ----- Original Message ----- From: "James David Rich" <james@eaerich.com> To: <RPG400-L@midrange.com> Sent: Monday, April 16, 2001 11:52 AM Subject: Re: Variable length MODS > On Fri, 13 Apr 2001, Peter Dow wrote: > > > I believe the compiler puts in upper boundary checking based on what you > > enter as the dimensions or occurrences of the array or data structure, i.e. > > but this is my point - there should not be an upper boundary on the size > of a variable if you don't say "I want a variable of this size". You > should be able to define what a variable *looks* like without actually > saying how big it is. That's what pointers and alloc are for. > > > no relation to the pointer. In the example I gave Tom, there's an array > > with a DIM(9999). If only enough memory is allocated for 3 array entries, > > what happens when he references entry 4? As far as the compiler is > > concerned, 4 is well within the defined upper boundary of 9999, but in fact > > no memory has been allocated for that entry and it moves into uncharted > > territory, but does not (as far as I know) give an error. > > Note: the example below is pseudo-pseudo code :) > > So if I want a variable (in this case a struct strdata) that has a: > { > char(length 1) > int(32 bit) > zone(5,2) > } > and I give DIM(1) but base it on a pointer ptr then I should be able to > > alloc sizeof(strdata) ptr > > and get the first occurence of strdata. Then I ought to be able to > > alloc sizeof(strdata) ptr > > and get another occurence of strdata, or the second occurence. But if the > compiler is limiting me to DIM(1) I cannot access my second occurence, > even though it is perfectly legitimate. I really don't want to use DIM at > all, rather just use struct strdata to define what my memory that I'm > allocating looks like. Then I should be able to allocate as much as I > want and as long as I don't try to access memory beyond what is allocated > (by moving my pointer too far or something) all should be well. > > Or is there something wrong with this thinking? > > James Rich > james@eaerich.com > > +--- > | This is the RPG/400 Mailing List! > | To submit a new message, send your mail to RPG400-L@midrange.com. > | To subscribe to this list send email to RPG400-L-SUB@midrange.com. > | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. > | Questions should be directed to the list owner/operator: david@midrange.com > +--- +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
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.