Search code examples
adamemory-address

Initialise type from address


I want to initialise a type from a System.address. For example :

generic
    type T_Generic is private;
package MyPackage is
    G_Addr : System.Address;
    procedure Register (myAddr : System.address);
    procedure MyProcedure (myAddr : System.address);
end MyPackage;

package body MyPackage is
    procedure Register(myAddr : System.address)
    is
        G_Addr := myAddr;
    end MyProcedure;

    procedure MyProcedure (myAddr : System.address)
        myVar : T_Generic with address => myAddr;
    is
        if (myAddr = G_Addr)
        then
            -- work with myVar 
        end if;
    end MyProcedure;
end MyPackage;
    

But I cannot compile this piece of code myVar : T_Generic with address => myAddr; :

aspect specification is an Ada 2012 feature

unit must be compiled with -gnat2012 switch

I cannot change compilation's options, how can I do ?


Solution

  • But I cannot compile this piece of code myVar : T_Generic with address => myAddr;:

    aspect specification is an Ada 2012 feature

    unit must be compiled with -gnat2012 switch

    My_Address  :  Constant System.Address:= To_Address( 16#DEAD_BEEF# );
    My_Variable :  Whatever;
    For My_Variable'Address use My_Address;