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: a07f3367d7,f5e42181cacdac63 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!m7g2000prd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Variant record assignment fails discriminant check Date: Wed, 2 Sep 2009 08:33:07 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <577dcd1b-5384-408f-abf5-440e6ebd651a@a7g2000yqo.googlegroups.com> <7614be09-c46f-44f8-a04b-090af7c1bf13@k13g2000prh.googlegroups.com> <2e307dac-ae36-46a3-813f-09271215cca3@o9g2000yqj.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1251905587 1946 127.0.0.1 (2 Sep 2009 15:33:07 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 2 Sep 2009 15:33:07 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m7g2000prd.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8113 Date: 2009-09-02T08:33:07-07:00 List-Id: On Sep 2, 8:09=A0am, vldmr wrote: > On Sep 2, 9:52=A0am, Adam Beneschan wrote: > > > On Sep 2, 7:25=A0am, vldmr wrote: > > > Only if the actual parameter is mutable when you call the procedure. > ... > > > OK, so I'll bet your next question is: So how do I declare an object > > to be unconstrained (mutable), but give its discriminant an initial > > value other than the default (X520CommonName_teletexString)? > > > =A0 =A0WXY : t_X520CommonName :=3D (choice_Id =3D> > > X520CommonName_printableString, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 others =3D>= <>); > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 -- Adam > > Oh, thank, make sense now. At least I see where my problem is. In my > case WXY is actually declared as access to record, and is initialized > using Unchecked_Conversion from external memory address, pointing to > zero filled memory. > > Any advice how to declare an access to variant record to be mutable? I don't think the language will let you do this, directly. If you declare a type "type acc_t_X520CommonName is access all t_X520CommonName", and an object Acc of this access type, then Acc.all is assumed to be constrained, and if you pass Acc.all to your procedure, the procedure can't change it. (The original motivation was, I think, that you can declare a constrained subtype of the access type; if you have an access object of that constrained subtype and make it point to an object with the correct discriminant, it would be bad if the language let you change the discriminant via a different, unconstrained, access object. There have been some language changes regarding discriminants on access types, and I'm not familiar with all of them, so maybe you can do things you previously couldn't. I'm not sure.) However, you can get around this by embedding the variant record inside another record: type Rec is record Name : t_X520CommonName; end record; type Acc_Rec is access all Rec; Now, if X has type Acc_Rec, you can pass X.Name to your procedure, and it will be unconstrained (and therefore mutable). This is a workaround that I've used extensively in my own code, by the way. -- Adam