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: 103376,74b958f114ec4924 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "news.broadpark.no" Newsgroups: comp.lang.ada References: <47d6ae9b$1@news.broadpark.no> <47d6c231$1_1@glkas0286.greenlnk.net> In-Reply-To: <47d6c231$1_1@glkas0286.greenlnk.net> Subject: Re: Type convertion Date: Tue, 11 Mar 2008 21:56:02 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6001.18000 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18000 NNTP-Posting-Host: 223.80-202-137.nextgentel.com X-Original-NNTP-Posting-Host: 223.80-202-137.nextgentel.com Message-ID: <47d6f184@news.broadpark.no> X-Trace: news.broadpark.no 1205268868 80.202.137.223 (11 Mar 2008 21:54:28 +0100) Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!nntp.gblx.net!nntp3.phx1!news.broadpark.no!not-for-mail Xref: g2news1.google.com comp.lang.ada:20304 Date: 2008-03-11T21:56:02+01:00 List-Id: "Stuart" wrote in message news:47d6c231$1_1@glkas0286.greenlnk.net... > "news.broadpark.no" wrote in message > news:47d6ae9b$1@news.broadpark.no... >>I have a simple question. I'm working on an Ada package I have received. >> >> - Is it possible to covert a Boolean to Integer in an easy way >> - Is it possible to covert an enum to Integer in an easy way > > Yes - but it depends on what integers you want. > > First, try checking up on the 'pos attribute for enumerated types - ARM > 3.5.5 > >> In the second question i typically have something like this: >> >> type My_Type is (AB, CD, EF, GH, IJ); >> >> Now, I have a declaration: >> >> MyTest : My_Type; >> >> The result is stored in MyTest. I'm writing an interface to a C based >> program and I need to convert it to Integer. I'm new to Ada, so any hint >> would help. > > If you are interfacing to a C program you perhaps should look at ARM Annex > B. For the interface you should use one of the Integer_n/Unsigned_n > types. > > If you simply want the mapping > AB => 0 > CD => 1 > EF => 2 > GH => 3 > IJ => 4 > > you could use > My_Type'pos(MyTest) > > Another way is to declare an array of Interfaces.Integer_n indexed by > My_Type which contains the values you want for each value of My_Type. > > You could use representation clauses for My_Type and > Unchecked_Conversions - but this is probably not a good idea. My_Type'pos and My_Type'val did the job. Thank's! Eirik