comp.lang.ada
 help / color / mirror / Atom feed
From: "Mike Silva" <mjsilva@jps.net>
Subject: Re: Unchecked_Conversion on different sized types -- problem?
Date: 2000/01/13
Date: 2000-01-13T00:00:00+00:00	[thread overview]
Message-ID: <j3tf4.441$dw3.15504@news.wenet.net> (raw)
In-Reply-To: 387E574A.146BD794@home.com


Bryce Bardin wrote in message <387E574A.146BD794@home.com>...
>Mike Silva wrote:
>
>> type T is ( BLACK, WHITE );
>>
>> for T use ( BLACK => 30, WHITE => 37 );
>
>  for T'Size use Integer'Size;

(Slapping head) Yep!

>> function T_to_int is new Unchecked_Conversion( T, Integer );
>>
>> T_val : T := BLACK;
>>
>> Text_IO.Put( Item => T_to_int( T_val )...
>
>> Mike
>
>But why use a representation clause for Color?

Umm, because that's how I would have done it in C? (I know, that carries a
lot of weight here!)  So, as I asked in another reply, why *ever* use a
representation clause for an enumeration?  To me, it's like my key ring:
I've got a CAR_KEY and a HOUSE_KEY, and at some point I want to actually
pass the key's raw data pattern to the lock, and having the raw data pattern
encoded directly in the enumeration seems cleaner than using a 'case'
statement or a translation array.
>
>  type Color is ( Black, White );
>--  for Color use ( Black => 30, White => 37 );
>  type String_Access is access String;
>  Command : array (Color) of String_Access := (new String'("30"), new
>String'("37"));
>begin
>  Text_Io.Put(Command(Color_Val).all);

This seems "busy", but my biggest objection would be having to enter the
same data twice (and keeping both sets consistent) -- isn't that always a
rich source of errors?

Mike







  reply	other threads:[~2000-01-13  0:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-13  0:00 Unchecked_Conversion on different sized types -- problem? Mike Silva
2000-01-13  0:00 ` reason67
2000-01-13  0:00 ` Jim Rogers
2000-01-13  0:00   ` Mike Silva
2000-01-13  0:00     ` James S. Rogers
2000-01-13  0:00 ` Bryce Bardin
2000-01-13  0:00   ` Mike Silva [this message]
2000-01-13  0:00     ` Mike Silva
2000-01-14  0:00       ` Bryce Bardin
2000-01-14  0:00         ` Mike Silva
2000-01-14  0:00   ` Matthew Heaney
2000-01-14  0:00 ` Werner Pachler
2000-01-14  0:00   ` reason67
2000-01-14  0:00   ` Bryce Bardin
2000-01-14  0:00 ` Wrap-Up (was Re: Unchecked_Conversion on different sized types -- problem?) Mike Silva
2000-01-15  0:00   ` Matthew Heaney
2000-01-15  0:00     ` Robert A Duff
2000-01-14  0:00 ` Unchecked_Conversion on different sized types -- problem? Vladimir Olensky
2000-01-14  0:00 ` Jeff Carter
2000-01-14  0:00 ` Keith Thompson
2000-01-16  0:00   ` David A. Cobb
replies disabled

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