comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Best representation for spares
Date: Sat, 15 Feb 2014 10:49:21 -0700
Date: 2014-02-15T10:49:21-07:00	[thread overview]
Message-ID: <ldo9b1$lmh$1@dont-email.me> (raw)
In-Reply-To: <8383f5d6-3f66-415b-ab3f-8801fa377a6b@googlegroups.com>

On 02/15/2014 09:06 AM, Rego, P. wrote:
> On Friday, February 14, 2014 7:19:20 AM UTC-2, Simon Wright wrote:
>> I'd much prefer to fill this space. And, on the whole, better with zeros
>> (unless, of course, 'unused' means 'don't even write to this bit').
>> Something like
>>     type Zero_Bit is range 0 .. 0;
>>     type Zero_Bits is array (Positive range <>) of Zero_Bit;
>>     for Zero_Bits'Component_Size use 1;
>>     type Auxiliary_Interrupt_Status_Type is
>>        record
>>           Mini_Uart_IRQ : Boolean;
>>           SPI_1_IRQ     : Boolean;
>>           SPI_2_IRQ     : Boolean;
>>           Spare         : Zero_Bits (3 .. 31);
>>        end record;
>>     pragma Pack (Auxiliary_Interrupt_Status_Type);
>>     for Auxiliary_Interrupt_Status_Type'Size use 32;
>
> Great, I will use this. Even more that the datasheet says 'Reserved, write zero, read as don't care'. Thanks.

Note that this does not guarantee that the contents of Spare are zeroes. 
Uninitialized objects, other than access objects, contain "stack junk", whatever 
happens to be in the memory that the object occupies. As a result, they may 
contain invalid values.

To force Spare to contain zeroes, you have to initialize it:

type Auxiliary_Interrupt_Status_Type is record
    Mini_Uart_IRQ : Boolean;
    SPI_1_IRQ     : Boolean;
    SPI_2_IRQ     : Boolean;
    Spare         : Zero_Bits (3 .. 31) := (3 .. 31 => 0);
end record;
for Auxiliary_Interrupt_Status_Type'Size use 32;

-- 
Jeff Carter
"In the frozen land of Nador they were forced to
eat Robin's minstrels, and there was much rejoicing."
Monty Python & the Holy Grail
70


  reply	other threads:[~2014-02-15 17:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14  1:07 Best representation for spares Rego, P.
2014-02-14  9:19 ` Simon Wright
2014-02-15 16:06   ` Rego, P.
2014-02-15 17:49     ` Jeffrey Carter [this message]
2014-02-15 20:21       ` Rego, P.
2014-02-15 19:55     ` Niklas Holsti
2014-02-15 20:25       ` Rego, P.
2014-02-15 21:35         ` Rego, P.
2014-02-16 10:02           ` Niklas Holsti
2014-02-16 13:40             ` Rego, P.
2014-02-16 16:26               ` Rego, P.
2014-02-16 18:50                 ` Niklas Holsti
2014-02-16 16:33               ` Niklas Holsti
2014-02-16 12:10           ` Simon Wright
2014-02-16 13:43             ` Rego, P.
2014-02-16 14:25               ` Robert A Duff
2014-02-16 16:21                 ` Rego, P.
2014-02-15 21:41         ` Jeffrey Carter
2014-02-15 22:37           ` Rego, P.
2014-02-15 22:41             ` Rego, P.
2014-02-16  0:39             ` Jeffrey Carter
2014-02-16 12:06         ` Simon Wright
2014-02-16 13:45           ` Rego, P.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox