From: Adam Beneschan <adam@irvine.com>
Subject: Re: Variant record assignment fails discriminant check
Date: Wed, 2 Sep 2009 07:52:28 -0700 (PDT)
Date: 2009-09-02T07:52:28-07:00 [thread overview]
Message-ID: <7614be09-c46f-44f8-a04b-090af7c1bf13@k13g2000prh.googlegroups.com> (raw)
In-Reply-To: 577dcd1b-5384-408f-abf5-440e6ebd651a@a7g2000yqo.googlegroups.com
On Sep 2, 7:25 am, vldmr <vldm...@gmail.com> wrote:
> For the folllowing variant record:
> ------------------------------------------
> type t_X520CommonName_Choice_Id is (
> X520CommonName_teletexString,
> X520CommonName_printableString
> -- more choices
> );
> type t_X520CommonName (choice_Id : t_X520CommonName_Choice_Id :=
> X520CommonName_teletexString) is record -- CHOICE
> case choice_Id is
> when X520CommonName_teletexString =>
> teletexString : t_TeletexString_Acc; -- TeletexString
> (SIZE (1..ub-common-name))
> when X520CommonName_printableString =>
> printableString : t_PrintableString_Acc; --
> PrintableString (SIZE (1..ub-common-name))
> -- ... more choices
> end case;
> end record;
> ----------------------------------
> the following code:
> ---------------------------------
> procedure BDec_X520CommonNameContent(tagId0 : t_Asn_Tag;v: out
> t_X520CommonName;) is
> begin
> case tagId0 is
> when
> 16#14000000# | -- UNIV PRIM TELETEXSTRING_TAG_CODE
> 16#34000000# -- UNIV CONS TELETEXSTRING_TAG_CODE
> =>
> declare
> teletexString : t_TeletexString_Acc;
> begin
> teletexString := Adr_2_t_TeletexString_Acc
> ( Asn1_Alloc ( t_TeletexString'Size / 8));
> Check_Asn1_Alloc (teletexString.all'Address,
> exceptProc);
> BDec_TeletexStringContent (tagId0, elmtLen0,
> teletexString.all, totalElmtsLen1, exceptProc);
> v := (choice_Id => X520CommonName_teletexString,
> teletexString => teletexString); -- CONSTRAINT_ERROR
> end;
> -- ... more choices
> end case;
> 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 := (choice_Id =>
X520CommonName_printableString,
others => <>);
-- Adam
next prev parent reply other threads:[~2009-09-02 14:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-02 14:25 Variant record assignment fails discriminant check vldmr
2009-09-02 14:52 ` Adam Beneschan [this message]
2009-09-02 15:09 ` vldmr
2009-09-02 15:33 ` Adam Beneschan
2009-09-02 16:09 ` vldmr
2014-05-12 0:31 ` maniyazhagan
2014-05-12 0:32 ` maniyazhagan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox