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!k13g2000prh.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 07:52:28 -0700 (PDT) Organization: http://groups.google.com Message-ID: <7614be09-c46f-44f8-a04b-090af7c1bf13@k13g2000prh.googlegroups.com> References: <577dcd1b-5384-408f-abf5-440e6ebd651a@a7g2000yqo.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 1251903151 25829 127.0.0.1 (2 Sep 2009 14:52:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 2 Sep 2009 14:52:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k13g2000prh.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:8111 Date: 2009-09-02T07:52:28-07:00 List-Id: On Sep 2, 7:25=A0am, vldmr wrote: > For the folllowing variant record: > ------------------------------------------ > type t_X520CommonName_Choice_Id is ( > =A0 =A0 =A0 =A0 X520CommonName_teletexString, > =A0 =A0 =A0 =A0 X520CommonName_printableString > -- more choices > =A0 =A0 ); > type t_X520CommonName (choice_Id : t_X520CommonName_Choice_Id :=3D > X520CommonName_teletexString) is record -- CHOICE > =A0 =A0 case choice_Id is > =A0 =A0 =A0 =A0 when X520CommonName_teletexString =3D> > =A0 =A0 =A0 =A0 =A0 =A0 teletexString : t_TeletexString_Acc; -- TeletexSt= ring > (SIZE (1..ub-common-name)) > =A0 =A0 =A0 =A0 when X520CommonName_printableString =3D> > =A0 =A0 =A0 =A0 =A0 =A0 printableString : t_PrintableString_Acc; -- > PrintableString (SIZE (1..ub-common-name)) > -- ... more choices > =A0 =A0 =A0end case; > end record; > ---------------------------------- > the following code: > --------------------------------- > =A0 =A0 procedure BDec_X520CommonNameContent(tagId0 : t_Asn_Tag;v: out > t_X520CommonName;) is > =A0 =A0 begin > =A0 =A0 =A0 =A0 case tagId0 is > =A0 =A0 =A0 =A0 =A0 =A0 when > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 16#14000000# | -- UNIV PRIM TELETEXSTRING= _TAG_CODE > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 16#34000000# =A0 -- UNIV CONS TELETEXSTRI= NG_TAG_CODE > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 declare > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 teletexString : t_TeletexString_A= cc; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 teletexString :=3D Adr_2_t_Telete= xString_Acc > ( Asn1_Alloc ( t_TeletexString'Size / 8)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Check_Asn1_Alloc (teletexString.a= ll'Address, > exceptProc); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BDec_TeletexStringContent (tagId0= , elmtLen0, > teletexString.all, totalElmtsLen1, exceptProc); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 v :=3D (choice_Id =3D> X520Common= Name_teletexString, > teletexString =3D> teletexString); -- CONSTRAINT_ERROR > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 end; > =A0 =A0 =A0 =A0 -- ... more choices > =A0 =A0 =A0 =A0end case; > =A0 =A0 end BDec_X520CommonNameContent; > -------------------------------------- > when executed produces 'discriminant check failed' error on assignment > to v. > > Why is that? As far as I understand the variable v shall be mutable. Only if the actual parameter is mutable when you call the procedure. Say you declare XYZ : t_X520CommonName (X520CommonName_printableString); ... BDec_X520CommonNameContent (Something, XYZ); XYZ is a constrained record. You wouldn't want BDec_X520CommonNameContent violating the constranit of XYZ by changing the discriminant, would you? On the other hand, if you declare ZYX : t_X520CommonName; ... BDec_X520CommonNameContent (Something, ZYX); ZYX is unconstrained, so it's OK for BDec_X520CommonNameContent to change the discriminant. This means that the compiler has to generate a little extra code to pass something to the procedure to tell it whether it's OK to change the discriminant. 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)? WXY : t_X520CommonName :=3D (choice_Id =3D> X520CommonName_printableString, others =3D> <>); -- Adam