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,bb6f4bd169077fb3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-07 16:24:25 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!postnews1.google.com!not-for-mail From: wojtek@power.com.pl (Wojtek Narczynski) Newsgroups: comp.lang.ada Subject: Re: Representing data differently Date: 7 Feb 2003 16:24:25 -0800 Organization: http://groups.google.com/ Message-ID: <5ad0dd8a.0302071624.384d0cf6@posting.google.com> References: <686be06c.0302070615.3943b629@posting.google.com> NNTP-Posting-Host: 80.55.195.178 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1044663865 3848 127.0.0.1 (8 Feb 2003 00:24:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 8 Feb 2003 00:24:25 GMT Xref: archiver1.google.com comp.lang.ada:33898 Date: 2003-02-08T00:24:25+00:00 List-Id: dallex@erols.com (Daniel Allex) wrote in message news:<686be06c.0302070615.3943b629@posting.google.com>... > In C I can represent the same data multiple ways using > structs and unions. Ada doesn't have unions, because they are unsafe. For example consider two simple types: type Foo is Integer range 1..12; type Bar is Integer range 20..100; If two variables, one of each type, were using the same chunk of memory the value of one would always be invalid. So if there were unions in Ada the compiler could not check your program for you. >How and can I do this in Ada? Often you can use a variant record instad of a union. There are also tricks, but of limited applicability. For example: declare F : Foo := 3; B : Bar; for B'Address use F'Address; begin -- Et violla! Constraint_Error B := B + 1; end; Another is to do Uncecked_Conversion between (constrained) access types. So this can be done, but you really need to know what you are doing. Regards, Wojtek