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,e037e74567eca23d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Question about Ada.Unchecked_Conversion Date: Fri, 29 Oct 2004 16:22:16 +0200 Message-ID: <1j6e3b4l7dt2u$.13qm82z687r64.dlg@40tude.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de UfjPMkq1BLpLOBUKRI9tWQVW36ekQNVLGwUrVit3t+4qE7IsQ= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:5865 Date: 2004-10-29T16:22:16+02:00 List-Id: 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