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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fb264cdd67c2f20f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Newsgroups: comp.lang.ada Subject: Re: A smaller self contained test case. Was: Compiler Bug or what I'm doing wrong? References: <05lkrrojfd.fsf@hod.lan.m-e-leypold.de> <1cfjjgsg6wwv4.44snml2yzt42$.dlg@40tude.net> <7sr71erb6j.fsf@hod.lan.m-e-leypold.de> From: M E Leypold Date: 24 Jun 2006 22:22:30 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Some cool user agent (SCUG) NNTP-Posting-Host: 88.72.218.241 X-Trace: news.arcor-ip.de 1151180188 88.72.218.241 (24 Jun 2006 22:16:28 +0200) X-Complaints-To: abuse@arcor-ip.de Path: g2news2.google.com!news2.google.com!news.germany.com!news.unit0.net!newsfeed.arcor-ip.de!news.arcor-ip.de!not-for-mail Xref: g2news2.google.com comp.lang.ada:4999 Date: 2006-06-24T22:22:30+02:00 List-Id: "Dmitry A. Kazakov" writes: > On 24 Jun 2006 15:53:32 +0200, M E Leypold wrote: > > > "Dmitry A. Kazakov" writes: > > > >> BTW, I wouldn't use discriminants with defaults, > > > > I'm perhaps misuing dicriminants anyway in that application. But they > > need to have defaults, since the disriminated records are fields in > > another record. Like > > > > type All_We_Know ( Internal_Data_Available : Boolean := True ) is record > > case Internal_Data_Available is > > when True => Secret_Data : ... ; > > ... > > end record; > > > > type ... is record > > Things_Known : All_We_Konw; > > ... > > end record; > > > > (Ok, stupid example, but you get ist: Data not to be given to an > > external data processing application can be supressed by the > > discriminant). > > All_We_Know looks much like a handle. Then I'd try to make it more OO, if No. That's just a stupid name. Actually it is an aggregate of information about a specific "case" which is not allowed to leave this specific office (privacy policy!) but the rest of the data is sent to a central office for statistical evaluation. No handle. The data in the record refers to the case. > you aren't allergic to it. What about tagged types? (:-)) Next time :-) (if there is a next time for an Ada project). Problem with this data structure is, that it is at the core of the application and rather specific. I don't dare ripping it out now. I followed Barnes' advice here: "wether it is appropriate to use a variant or tagged type, the key consideration is mutability". > procedure Get_Record is > F : File_Type; > S : Stream_Access; > begin > Open (F, Mode => In_File, Name => "tmp-bug3" ); > S := Stream (F); > for I in 1 .. 400 loop > declare > R : Customer_Description renames > Customer_Description'Input (S); Oops. My, that is a dirty trick -- but how do I return R? Hm, yes I can see how that would work. Perhaps :-). I'll see how I can fit that into the database module. > begin > Ada.Text_IO.Put_Line ("Read" & Integer'Image (I)); > end; > end loop; > Close (F); > end; > > begin > Write_Record; > Get_Record; > end; > > It should work with GNAT 3.15p / Windows. > > >> 1. You have the discriminant stored anyway (that was the choice about > >> having the defaults), so you cannot use one stored value of the > >> discriminant for all 400 fields, even if they had it same. > > > > Oops. That I don't understand. > > If the discriminant had no default, then Write would not store it. So if But it must. I don't know at the place whre the record is read which discriminant the record had. There can even be different discriminant in the records in the database (which you can't see in this example :-). > all 400 elements had the same value of the discriminant, you could first > store its value manually (Boolean'Write) and then use 'Write for each > element. When reading you'd read the discriminant value once and then use > Read on a variable constrained to that value: Ah no. Unfortunately I have many of discriminants in many places (they reflect a more complicated business logic when data can/must be available) and they can all change independently. > So it is safe to use it, at least to work the bug around. Yep. At least until an new Gnat ciomes up for me. Regards and thanks! Maybe your trick will spare me a lot of gray hairs. Regards -- Markus