comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Question about Ada.Unchecked_Conversion
Date: Fri, 29 Oct 2004 16:22:16 +0200
Date: 2004-10-29T16:22:16+02:00	[thread overview]
Message-ID: <1j6e3b4l7dt2u$.13qm82z687r64.dlg@40tude.net> (raw)
In-Reply-To: m2oeil3d4x.fsf@mac.scrogneugneu.org

On Fri, 29 Oct 2004 14:46:54 +0200, Eric Jacoboni wrote:

> There is something i've probably not understood about
> Ada.Unchecked_Conversion behavior, despite readings of Barnes and
> RM95.
> 
> To illustrate my pb, let a String in which i want to count
> various separators :
> 
> subtype T_Phrase is String(1..Lg_Max);
>    
> type T_S�parateur is (' ', Ht, Lf, ',' ,';', ':', '.', '?', '!');
> for T_S�parateur'Size use Character'Size;
> 
> function Char_To_S�parateur is 
>       new Ada.Unchecked_Conversion(Character, T_S�parateur);
> 
> Ma_Phrase : T_Phrase;
> 
> What i want to do is simply a test like this, in order to find
> characters that are also separators:
> 
> if Char_To_S�parateur(Ma_Phrase(I)) in T_S�parateur then 
>   ...
> end if;
> 
> But this test always fails and i don't understand why. The logic seems
> correct so i suppose it's a misunderstanding of Unchecked_Conversion?

The semantics of Unchecked_conversion differs from what you seem to imply.
What you want is probably just:

with Ada.Strings.Maps;        use Ada.Strings.Maps;
with Ada.Characters.Latin_1;  use Ada.Characters.Latin_1;
...
Separators : constant Character_Set := To_Set (" .,:!?" & HT & LF);
...
if Is_In (Ma_Phrase (I), Separators) then
   ...
end if;

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



  reply	other threads:[~2004-10-29 14:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-29 12:46 Question about Ada.Unchecked_Conversion Eric Jacoboni
2004-10-29 14:22 ` Dmitry A. Kazakov [this message]
2004-10-29 14:26 ` Jean-Pierre Rosen
2004-10-29 15:15 ` Nick Roberts
2004-10-29 15:47   ` Eric Jacoboni
2004-10-30 10:23     ` skidmarks
2004-10-30 16:30       ` Nick Roberts
2004-10-30 17:18         ` Eric Jacoboni
replies disabled

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