From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,13703514e3723cbe X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-17 03:44:20 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!chcgil2-snf1.gtei.net!news.gtei.net!news.binc.net!kilgallen From: Kilgallen@eisner.decus.org.nospam (Larry Kilgallen) Newsgroups: comp.lang.ada Subject: Re: Variable sizes for record fields Date: 17 Aug 2001 05:44:12 -0500 Organization: LJK Software Message-ID: <8eI27ybFqL0Y@eisner.encompasserve.org> References: <9l7qon$d78$1@nntp9.atl.mindspring.net> NNTP-Posting-Host: eisner.encompasserve.org X-Trace: grandcanyon.binc.net 998044652 15671 192.135.80.34 (17 Aug 2001 10:37:32 GMT) X-Complaints-To: abuse@binc.net NNTP-Posting-Date: Fri, 17 Aug 2001 10:37:32 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:12039 Date: 2001-08-17T05:44:12-05:00 List-Id: In article , David Brown writes: > Larry Kilgallen wrote: > >>> I have recently encountered a concrete example of the need for something >>> like this. The application is storing variable sized data fields in fixed >>> length records (say disk sectors). The block is defined as a large string. >>> The beginning of the block contains lengths for each of the variable sized >>> fields. The data items start at the end of the record and work their way >>> backward. >> >> This sounds to me like the beginning of the record definition is the >> discriminant values and the end of the record is the text fields. >> The one trick, to achieve a fixed size, is to have an extra discriminant >> to define the size of the "middle". This is based on my experience with >> Ada83. Perhaps Ada95 lets you do more "math" with discriminant values >> to avoid the need for an extra discriminant. > > To make this work, I would need several things. First of all, my > discriminants would have to be an array of values whose size is based on > another discriminant. An Ada record type always has a fixed number of discriminants (often zero). > Second, I need to represent things (like the size of the middle) without > taking up any space. They need to be computed and that's it. The sizes of > each of the other text strings needs to be based on the array of > discriminant sizes. Check into the Ada95 angle. > Third, I need to be able to change the structure in-place. It is > complicated code, and I don't think that the compiler would understand all > of the cases involved, even if you could arbitrarily assign to > discriminants like this. POINTER_TO_NEW_RECORD := new MY_RECORD_TYPE ( SIZE_1 => 42, SIZE 2 => 42, SIZE_3 => 42, SIZE_REST => 42 ); > I wasn't even able to make a simple record containing a discriminant and a > string of that length and come up with a way to make the particular > discriminant a constant and not take up any storage. That is just the point. Ada requires that the discriminants of the record can be recognized at run time. There is no way to do that without taking up space.