From: Simon Wright <simon@pushface.org>
Subject: Re: Array slicing question
Date: Mon, 07 Jul 2014 09:04:10 +0100
Date: 2014-07-07T09:04:10+01:00 [thread overview]
Message-ID: <lyfvidegsl.fsf@pushface.org> (raw)
In-Reply-To: 91b81cfc-2faa-4cc5-9c9c-0dc663b67a68@googlegroups.com
Mike Silva <mjsilva697@gmail.com> 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);
next prev parent reply other threads:[~2014-07-07 8:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-07 7:31 Array slicing question Mike Silva
2014-07-07 8:04 ` Simon Wright [this message]
2014-07-07 13:34 ` G.B.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox