Use Ada 2012 aspects to specify variable locations


Earlier with Ada 95 and Ada 2005, if you wanted to put a variable to some specific memory location, you had to use 'for Variable'Address use X' statement and Volatile pragma for that:

My_Var : Unsigned_32;
for My_Var'Address use System'To_Address (16#FF00#);
pragma Volatile (My_Var);

With Ada 2012 this becomes simpler when you use aspects:

My_Var : Unsigned_32 with
  Volatile, Address => System'To_Address (16#FF00#);

Here is another real life example from STM32F4 code:

package STM32F4 is
   GPIOC_ADDRESS : constant := 16#4002_0800#;
   GPIOC_MODE_ADDRESS : constant := GPIOC_ADDRESS + 0;

   GPIOC_MODE : Interfaces.Unsigned_32 with
      Volatile, Address => System'To_Address (GPIOC_MODE_ADDRESS);
end STM32F4;