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,5e54ec0ce937978 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!news.mv.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: String literals and wide_string literals - how? Date: Sat, 21 Apr 2007 21:00:45 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1177063665.093083.241580@e65g2000hsc.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1177203645 7793 192.74.137.71 (22 Apr 2007 01:00:45 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 22 Apr 2007 01:00:45 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:MtM/04PTnp9BtuBxm9zphlz5xUU= Xref: g2news1.google.com comp.lang.ada:15202 Date: 2007-04-21T21:00:45-04:00 List-Id: "Jeffrey R. Carter" writes: > Robert A Duff wrote: >> type Bit is ('0', '1'); >> type Bit_String is array (Positive range <>) of Bit; >> pragma Pack(Bit_String); >> X: constant Bit_String := "01011110"; >> Bit is a character type, and Bit_String is a string type. >> X can fit in 8 bits, by the way. > > for Bit'Size use 1; Bit'Size is 1 by default, so I suppose: pragma Assert(Bit'Size = 1); would be a better way to express this, in case you care. > for Bit_String'Component_Size use Bit'Size; > > subtype Byte_String is Bit_String (1 .. 8); > > Y : constant Byte_String := "00001111"; > pragma Assert (Y'Size = Y'Length); Y'Size might well be 32 on some implementations. But that's OK -- Byte_String'Size should be 8. > type Byte is mod 2 ** 8; > for Byte'Size use 8; > > function To_Byte is new Ada.Unchecked_Conversion > (Source => Byte_String, Target => Byte); > > Z : constant Byte := To_Byte (Y); > > What is Z and 1? 0 or 1, depending on the implementation. I'm not sure what your point is, here. Unchecked_Conversion depends on implementation choices (in this case, based on endianness), and is therefore implementation defined. So? Types Bit and Bit_String above have well-defined portable semantics. Patient: "Doc, It hurts when I Unchecked_Convert." Doctor: "So don't do that." ;-) - Bob