comp.lang.ada
 help / color / mirror / Atom feed
* Default values
@ 2016-12-25  9:23 Simon Wright
  2016-12-25 11:53 ` Jeffrey R. Carter
  2016-12-25 17:12 ` AdaMagica
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Wright @ 2016-12-25  9:23 UTC (permalink / raw)


Given

   with Ada.Real_Time;

   package Sbus.IMU is

      subtype Radians_Per_Second is Float;
      subtype Acceleration is Float;
      subtype Milligauss is Float;

      type Update (Magnetometer_Data_Present : Boolean := False) is record
         Time_Valid : Ada.Real_Time.Time;

         Gx, Gy, Gz : Radians_Per_Second;
         Ax, Ay, Az : Acceleration;

         case Magnetometer_Data_Present is
            when True =>
               Mx, My, Mz : Milligauss;
            when False =>
               null;
         end case;
      end record;

      protected Updater is
         procedure Put_New_Data (Data : Update);
         entry Get_New_Data (Data : out Update);
         procedure Get_Latest_Data (Data : out Update);
      private
         New_Data_Present : Boolean := False;
         Latest_Data : Update := (others => <>);
      end Updater;

   end Sbus.IMU;

is the line

         Latest_Data : Update := (others => <>);

legal? If so, what does it mean? (I've looked at the ARM for Record
Aggregates, 4.3.1, and Record Types. 3.8, and am no wiser).

I do realise that I need to put some default initializations in (or else
supply a proper initialization for Latest_Data!)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Default values
  2016-12-25  9:23 Default values Simon Wright
@ 2016-12-25 11:53 ` Jeffrey R. Carter
  2016-12-25 17:12 ` AdaMagica
  1 sibling, 0 replies; 5+ messages in thread
From: Jeffrey R. Carter @ 2016-12-25 11:53 UTC (permalink / raw)


On 12/25/2016 10:23 AM, Simon Wright wrote:
>
> is the line
>
>          Latest_Data : Update := (others => <>);
>
> legal? If so, what does it mean? (I've looked at the ARM for Record
> Aggregates, 4.3.1, and Record Types. 3.8, and am no wiser).

Yes, it's legal. It means the same thing as

Latest_Data : Update;

-- 
Jeff Carter
"Sheriff murdered, crops burned, stores looted,
people stampeded, and cattle raped."
Blazing Saddles
35

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Default values
  2016-12-25  9:23 Default values Simon Wright
  2016-12-25 11:53 ` Jeffrey R. Carter
@ 2016-12-25 17:12 ` AdaMagica
  2016-12-25 20:20   ` Simon Wright
  2016-12-27 23:32   ` Randy Brukardt
  1 sibling, 2 replies; 5+ messages in thread
From: AdaMagica @ 2016-12-25 17:12 UTC (permalink / raw)


See RM 4.3.1. In your case,
  Latest_Data: Update := (others => <>);
  Latest_Data: Update;
mean the same.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Default values
  2016-12-25 17:12 ` AdaMagica
@ 2016-12-25 20:20   ` Simon Wright
  2016-12-27 23:32   ` Randy Brukardt
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Wright @ 2016-12-25 20:20 UTC (permalink / raw)


AdaMagica <christ-usch.grein@t-online.de> writes:

> See RM 4.3.1. In your case,
>   Latest_Data: Update := (others => <>);
>   Latest_Data: Update;
> mean the same.

Thanks to you & Carter. My problem was not being able to see the wood
for the trees (not helped by looking at the AARM).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Default values
  2016-12-25 17:12 ` AdaMagica
  2016-12-25 20:20   ` Simon Wright
@ 2016-12-27 23:32   ` Randy Brukardt
  1 sibling, 0 replies; 5+ messages in thread
From: Randy Brukardt @ 2016-12-27 23:32 UTC (permalink / raw)


"AdaMagica" <christ-usch.grein@t-online.de> wrote in message 
news:284b95e9-f48a-498f-b3b4-d2dd148fad4a@googlegroups.com...
> See RM 4.3.1. In your case,
>  Latest_Data: Update := (others => <>);
>  Latest_Data: Update;
> mean the same.

Right. Each component is "initialized by default", which for Float and 
subtypes thereof means that they're uninitialized. Probably not what you 
want, but well-defined.

                                    Randy.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-12-27 23:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-25  9:23 Default values Simon Wright
2016-12-25 11:53 ` Jeffrey R. Carter
2016-12-25 17:12 ` AdaMagica
2016-12-25 20:20   ` Simon Wright
2016-12-27 23:32   ` Randy Brukardt

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