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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ec264956a9d7e36a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-11 11:35:53 PST From: "Martin Dowie" Newsgroups: comp.lang.ada References: <2sk5nInklHl1@eisner.encompasserve.org> <3c680086@pull.gecm.com> <6Hi6zB5TJ9qK@eisner.encompasserve.org> Subject: Re: Restrictions on compilers for Microsoft's .NET project Date: Mon, 11 Feb 2002 19:20:50 -0000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-Mimeole: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: ed125012.sd.edinbr.gmav.gecm.com Message-ID: <3c68198b$1@pull.gecm.com> X-Trace: 11 Feb 2002 19:20:43 GMT, ed125012.sd.edinbr.gmav.gecm.com Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news-x2.support.nl!newsfeed.wirehub.nl!btnet-peer!btnet-peer0!btnet-feed5!btnet!newreader.ukcore.bt.net!pull.gecm.com!ed125012.sd.edinbr.gmav.gecm.com Xref: archiver1.google.com comp.lang.ada:19882 Date: 2002-02-11T19:20:50+00:00 List-Id: > Certainly I am not expecting to be able to change variants on the fly, > but I have a lot of code that receives an access value denoting a > record and I have to check the value of a discriminant to determine > which fields of the record are available to me. If I get it wrong > Compaq Ada will detect my error just as surely as it will detect an > out-of-range value of the discriminant. Those possibly-present > fields from various variants are located at the same offsets as > each other. > > The Microsoft publication I quoted described this as "unsafe". Is > this prohibited by .NET ? Is it allowed in Ada95 as in Ada83 ? Well, I can see how this would be "unsafe" in C-style languages but with all checks in place Ada programs will prevent you from assigning to variant fields if the discriminant doesn't allow it. So in: type A_Variant (Value : Foo := Foo'First) is record case Value is when Bar1 => Int : Integer; when Bar2 => Bool : Boolean; end case; end record; if you wanted to have a data item with Value = Bar2 but an integer value assigned to the memory area that Bool occupies you can, but only by using a big ugly thing like an unchecked conversion. otherwise, if you want to have 'Bool' assigned a value, you have to change the discriminant to Bar2 at the same time.