comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: I need a little help - it's been a long time - with enumeration type  and for use representation
Date: Sat, 14 Nov 2009 10:24:43 +0100
Date: 2009-11-14T10:24:47+01:00	[thread overview]
Message-ID: <hytbzsmqqtiv$.14imm3x5m8syh$.dlg@40tude.net> (raw)
In-Reply-To: hdkj2f$viu$1@news.tornevall.net

On Fri, 13 Nov 2009 14:30:44 -0700, Jeffrey R. Carter wrote:

> Dmitry A. Kazakov wrote:
>> 
>> I do it differently. I have the pattern:
>> 
>> procedure Get (Text : String; Pointer : in out Integer; Value : out Type)
>> 
>> which I consistently deploy everywhere. Get takes a textual representation
>> of Type from Text at Pointer and advances Pointer to the first position
>> following it. The result is returned though Value.
>> 
>> However, yes, usually I use a plain type conversion:
>> 
>>    Get (Text, Pointer, Integer (Value));
>> 
>> rather than Type'Val (when I am too lazy to instantiate the generic
>> packages once again with Type)
> 
> I still don't see where you would use 'Val.

As I said in place of type conversion. If you have some bit pattern as a
number you can use either Val or type conversion:

   declare
      N : Integer;
   begin
      Get (Text, Pointer, N);
      Value := Type'Val (N);   --- or Value := Type (N)
      ...

Type'Val is probably semantically cleaner than conversion. Then there are
cases where conversion cannot be used, e.g. for formal discrete types in
generics. There you have to use 'Val instead of conversion, 'Suc instead of
+1 etc.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2009-11-14  9:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-13 16:03 I need a little help - it's been a long time - with enumeration type and for use representation Harry Tucker
2009-11-13 17:24 ` Niklas Holsti
2009-11-13 17:24 ` Dmitry A. Kazakov
2009-11-13 18:48   ` Jeffrey R. Carter
2009-11-13 19:13     ` Dmitry A. Kazakov
2009-11-13 20:32       ` Jeffrey R. Carter
2009-11-13 20:53         ` Dmitry A. Kazakov
2009-11-13 21:30           ` Jeffrey R. Carter
2009-11-14  9:24             ` Dmitry A. Kazakov [this message]
2009-11-13 18:46 ` Jeffrey R. Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox