comp.lang.ada
 help / color / mirror / Atom feed
From: "Stuart" <stuart@0.0>
Subject: Re: volatile vs volatile_components
Date: Thu, 6 Nov 2008 10:18:31 -0000
Date: 2008-11-06T10:18:31+00:00	[thread overview]
Message-ID: <4912c029$1_1@glkas0286.greenlnk.net> (raw)
In-Reply-To: 046f172d-90f7-4a23-a181-dd1461ebd94b@i18g2000prf.googlegroups.com

"REH" <spamjunk@stny.rr.com> wrote in message 
news:046f172d-90f7-4a23-a181-dd1461ebd94b@i18g2000prf.googlegroups.com...
> Is there a difference between defining an array with pragma volatile
> vs volatile_components? The standard says that if the object is
> volatile, its components are volatile. So, if the object is defined as
> having volatile components, what does that say--if anything--about the
> object as a whole?

As Adam Beneschan notes elsewhere it is an interesting question and the LRM 
does not seem to shed much light on it.

I was interested in what meaning might be attributed to a whole array 
assignment - does the LRM define a particular order in which the elements 
must be accessed.

Also in an assignment such as:
     A2 := A1;
should the whole of A1 be read (buffered) before the write to A2 commences 
(I think it should - but I am no language lawyer).

I tried the code below with a compiler here and it seemed to perform both 
whole array assignments as direct element by element copies (read then write 
of an element).  However, it also seemed to make a complete dogs dinner of 
the first case by effectively implementing:
        W := X;  -- copied element by element!!
        W := W;  -- copied element by element!!

Seemingly an explicit violation of the rules!!  A bug report methinks - but 
it would be interesting to be clear on exactly what the LRM requires it to 
do before submitting it.

package T is
   pragma Elaborate_Body;

   type Element is mod 2**16;

   type Index is range 1..100;

   type V_Array is array(Index) of Element;
   pragma volatile(V_Array);

   type VC_Array is array(Index) of Element;
   pragma volatile_components(VC_Array);

   W,X : V_Array;
   pragma volatile(W);
   pragma volatile(X);

   Y,Z : VC_Array;

   E : Element;
end T;

package body T is
begin
   -- Whole array assignments.
   W := X;
   Y := Z;

   -- Element by element assignments for comparison.
   for i in W'range loop
      X(i) := W(i);
   end loop;

   for i in Y'range loop
      Z(i) := Y(i);
   end loop;
end T;

-- 
Stuart 





      parent reply	other threads:[~2008-11-06 10:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-05 15:00 volatile vs volatile_components REH
2008-11-06  1:21 ` Adam Beneschan
2008-11-06  9:25   ` Dmitry A. Kazakov
2008-11-06 16:23     ` Adam Beneschan
2008-11-06 10:18 ` Stuart [this message]
replies disabled

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