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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Array slicing question Date: Mon, 07 Jul 2014 09:04:10 +0100 Organization: A noiseless patient Spider Message-ID: References: <91b81cfc-2faa-4cc5-9c9c-0dc663b67a68@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="117da9042fa4d6f5956a9b8f72035635"; logging-data="6398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/R/uJ6v+jPCLq5HBJzUrNlQiuzhl5b+1s=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:HBIUF7n0PMHchwx0/L+QGh/lKZY= sha1:8JQJpxHpUOjOj/vs1EIE9LjzXqY= Xref: news.eternal-september.org comp.lang.ada:20767 Date: 2014-07-07T09:04:10+01:00 List-Id: Mike Silva writes: > I (I being an Ada novice) am still fiddling around with writing 4 bits > of LCD display data into a 32-bit GPIO register. I have this: > > type Bits_1 is mod 2**1 with Size => 1; > type Bits_32x1 is array (0 .. 31) of Bits_1 with Pack, Size => 32; > type Bits_8x1 is array (0 .. 7) of Bits_1 with Pack, Size => 8; > > and I want to do things like this: > > a32 : Bits_32x1; > a8 : Bits_8x1; > ... > a32(4..7) := a8(4..7); > > This is not allowed, apparently, because a32 and a8 are different > types (even though the elements of the arrays are the same type, so > I'm a little confused, but OK). > > So can I do this? I'm guessing if Bits_32x1 and Bits_8x1 were both > subtypes of the same type, I could do it - is this correct? But I > don't know how to declare such a type, especially given the Pack and > Size attributes. > > I note that (ref confusion above) I CAN do this: > > for i in 4..7 loop > gpio32(i) := b8(i); because the components _are_ the same type. Would this help? type Bits is array (Natural range <>) of Boolean with Pack; subtype Bits_32 is Bits (0 .. 31); subtype Bits_8 is Bits (0 .. 7); A32 : Bits_32 with Size => 32; A8 : Bits_8 with Size => 8; ... A32 (4 .. 7) := A8 (4 .. 7);