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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 1014db,edd83659ff9286d0 X-Google-NewGroupId: yes X-Google-Thread: 103376,1cd9f7e5a0d12003 X-Google-NewGroupId: yes X-Google-Thread: 1094ba,1cd9f7e5a0d12003 X-Google-NewGroupId: yes X-Google-Attributes: gid4516fb5702,gida07f3367d7,gid8d3408f8c3,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.204.143.145 with SMTP id v17mr2363720bku.7.1337682599634; Tue, 22 May 2012 03:29:59 -0700 (PDT) Path: e27ni38713bkw.0!nntp.google.com!news1.google.com!goblin3!goblin2!goblin.stu.neva.ru!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 22 May 2012 12:29:59 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.c,comp.lang.ada,comp.lang.fortran Subject: Re: condition true or false? -> (-1 < sizeof("test")) References: <95634f38f6ee0d116da523fdc2c9f5ca@dizum.com> <00240c6dd26962f50d5c57a933c137ef@dizum.com> In-Reply-To: Message-ID: <4fbb6aa6$0$9522$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 22 May 2012 12:29:58 CEST NNTP-Posting-Host: 4faa7a65.newsspool1.arcor-online.net X-Trace: DXC=[eDJo@<<[:_V0Pe9PRnbJ\ic==]BZ:af^4Fo<]lROoRQnkgeX?EC@@P_VX:i1JEGkZPCY\c7>ejVX^Gf^7WfZnJ[O:1\e3 On 22.05.12 03:45, glen herrmannsfeldt wrote: > I don't know how ADA treats signed values, or how its bitwise > operators work. This is still posted to the ADA group, though. A feature of Ada (a lady's first name; some older book's have capitals in titles) is that you would not normally have to worry; you still can if you like, or must. First, one cannot store signed (unsigned) values in places whose type is unsigned (signed) unless using force such as explicit type conversion, or Unchecked_Conversion. Different types, no implicit conversions, as mentioned in the thread. As needed, one selects from the three kinds of types that have logical operations, Boolean, modular, and packed array of Boolean. Some redundant assertions in the following. with Interfaces; -- for unsigned modular "hardware" types with Ada.Unchecked_Conversion; procedure Bops is -- modular types with modular arithmetic and Boolean ops: type U8 is mod 2**8; pragma Assert (U8'Pred (0) = -1); pragma Assert (U8'Succ (U8'Last) = 0); X8 : U8 := 2#1111_1111#; --X9 : U8 := 2#1111_1111_1#; -- compiler rejects, value not in range X1 : U8 := -1; -- modular arithmetic X0 : U8 := not 0; -- has Boolean ops pragma Assert (X0 = X1); pragma Assert (X1 = 2#1111_1111#); -- convert from signed: type S8 is range -128 .. 127; for S8'Size use 8; function To_U8 is new Ada.Unchecked_Conversion (S8, U8); I8 : S8 := -1; -- a negative signed value --XI : U8 := U8 (I8); -- type conv will raise! value out of range XU : U8 := To_U8 (I8); -- o.K., not checked pragma Assert (XU = 8#377#); -- unsinged_N "hardware types" when supported by the compiler; -- includes shifting operations and such, is modular use type Interfaces.Unsigned_64; -- import "+" for literals U64 : Interfaces.Unsigned_64 := 16#FFFF_FFFF_FFFF_0000# + 2#101#; -- types for convenient access to individual bits type Bitvec is array (Natural range <>) of Boolean; pragma Pack (Bitvec); -- guaranteed subtype Bitvec_8 is Bitvec (0 .. 7); Y : Bitvec (0 .. 11) := (5 => True, others => False); pragma Assert (Y(5) and not Y(11)); Z : Bitvec_8; Toggle : constant Bitvec_8 := (others => True); begin Y (11) := True; Z := Y(8 - 6 + 1 .. 8) & Y(10 .. 11) xor Toggle; pragma Assert (Z = (True, True, False, True, True, True, True, False)); end Bops; -- Georg