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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d9e62a9b5f6f9797 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-25 12:37:10 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dewar@gnat.com (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: boolean array Date: 25 Jan 2002 12:37:10 -0800 Organization: http://groups.google.com/ Message-ID: <5ee5b646.0201251237.766bac75@posting.google.com> References: NNTP-Posting-Host: 205.232.38.244 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1011991030 2722 127.0.0.1 (25 Jan 2002 20:37:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 25 Jan 2002 20:37:10 GMT Xref: archiver1.google.com comp.lang.ada:19312 Date: 2002-01-25T20:37:10+00:00 List-Id: Christoph Grein wrote in message news:... > Foo : array (some_range) of Boolean; > ... > Any_False_Present : constant Boolean := Foo /= (some_range => True); > > But faster/preferred ?? If the array is packed, this should be fast. Here using the latest version of GNAT, is a source program: procedure K is type Rng is range 1 .. 8; type a is array (Rng) of Boolean; pragma Pack (a); va : a := (1 => False, others => True); begin if va = (Rng => True) then null; end if; end; And here is the expanded source program: procedure k is type k__rng is range 1 .. 8; type k__a is array (1 .. 8) of boolean; pragma pack (k__a); va : k__a := k__T6b!(16#FE#); begin if va = k__T10b!(16#FF#) then null; end if; return; end k; The ! here is unchecked conversion, and the implementation type of va is an 8 bit unsigned number, so as you can see this reduces the cost to a single comparison instruction. For those who need to see the asm to be convinced, here it is: .file "k.adb" gcc2_compiled.: ___gnu_compiled_ada: .text .align 2 .globl __ada_k __ada_k: pushl %ebp movl %esp,%ebp subl $4,%esp movb $254,-1(%ebp) cmpb $255,-1(%ebp) jne L2 L2: jmp L1 .align 2,0x90 L1: leave ret