Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Ada Programming/Pragmas/Volatile

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Pragmas Volatile __TOC__ pragma Volatile (local_name); Description Volatile is a representation pragma that can be used with types and variables to specify that the variable in question may suddenly change in value. For example, this may occur due to a device writing to a shared buffer. When this pragma is used, the compiler must suppress any optimizations that would interfere with the correct reading of the volatile variables. For example, two successive readings of the same variable cannot be optimized to just one or reordered. Compare with pragma Atomic, Atomic_Components, and Volatile_Components. Example type Video_Buffer is array (Natural range <>) of RGB_Value; Volatile (Video_Buffer); Incorrect usage Portability Ada versions This pragma is available in Ada 95 and Ada 2005 (Annex C, a specialized needs annex). In Ada 83 there is not an standard pragma completely equivalent to Volatile. However, pragma Shared is similar to Atomic (although it is obsolescent since Ada 95), pragma Shared (was Ada is almost ....) Robert Dewar 1996-02-17 comp.lang.ada http://groups.google.com/group/comp.lang.ada/msg/eeee3a7515837ea2 2008-05-28 pragma Atomic is QUITE different from pragma Volatile. pragma Atomic in Ada is essentially identical to pragma Shared in Ada 83. pragma Volatile in Ada is essentially identical to volatile in C, and is a feature that is not available in Ada 83. and some compilers added an implementation-defined pragma for this purpose. GNAT Pro Reference Manual Implementation Defined Pragmas https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/implementation_defined_pragmas.html#pragma-volatile 2008-06-02 [pragma Volatile] was supplied in some Ada 83 compilers, including DEC Ada 83. The Ada 95 / Ada 2005 implementation of pragma Volatile is upwards compatible with the implementation in DEC Ada 83. Compilers Volatile is a standard pragma since Ada 95, defined in the Systems Programming Annex (Annex C). This is a specialized needs annex, therefore this pragma is not available in those compilers not implementing that annex. Platforms This pragma is portable to different architectures and operating systems. Interfacing In C/C++, the volatile qualifier is equivalent to this pragma. However, this C qualifier is used for both volatile and atomic data, even if atomic access is required. Therefore, when interfacing with existing C code, the programmer must read the code to understand whether the data needs atomic load and stores. If needed, the data should be marked in the Ada side with pragma Atomic or Atomic_Components, or with pragma Volatile or Volatile_Components otherwise. Coding rules Volatile objects without address clauses In many cases, when a volatile object is used for interfacing with a hardware device it should have an address clause too. gnatcheck: +R Volatile_Objects_Without_Address_Clauses AdaControl: check object_declarations (volatile_no_address); See also Wikibook Ada Programming Ada Programming/Pragmas Ada Programming/Pragmas/Atomic Ada Programming/Pragmas/Atomic Components Ada Programming/Pragmas/Volatile Components Ada Programming/Pragmas/Shared (obsolescent) Ada Reference Manual C 6 Shared Variable Control Ada 95 Rationale C 5 Shared Variable Control 3 Ada 95 Quality and Style Guide 6 2 4 Unprotected Shared Variables References Volatile Volatile