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=-0.9 required=5.0 tests=BAYES_00,FROM_NUMERIC_TLD autolearn=no 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 X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.65.235 Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!nntpfeed.proxad.net!news.side3.eu!zen.net.uk!dedekind.zen.co.uk!news-peer-lilac.gradwell.net!not-for-mail From: "Stuart" Newsgroups: comp.lang.ada References: <47d6ae9b$1@news.broadpark.no> Subject: Re: Type convertion Date: Tue, 11 Mar 2008 17:49:28 -0000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Response Message-ID: <47d6c231$1_1@glkas0286.greenlnk.net> X-Original-NNTP-Posting-Host: glkas0286.greenlnk.net NNTP-Posting-Host: 20.133.0.1 X-Trace: 1205257784 news.gradwell.net 514 dnews/20.133.0.1:28993 X-Complaints-To: news-abuse@gradwell.net Xref: g2news1.google.com comp.lang.ada:20301 Date: 2008-03-11T17:49:28+00:00 List-Id: "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. HTH -- Stuart If you simply want