โŒ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

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 ?

Define address depending on target

I have a gpr project with 2 targets :

mySources  := "My project files"
case Rules.Target is
    when "CASE1" =>
         mySources := "File1" & mySources 
    when "CASE2" =>
         mySources := "File2"  & mySources 
    when others =>
end case
for Source_Dirs use mySources 

I have File1 containing the variable local_Address :

local_Address : constant System.Address := Function_to_get_Address();

On a commonFile I want to do :

-- Type definition
type My_Array_Type is array (Boolean) of My_Type;

-- Variable definition
My_Array : My_Array_Type;
for My_Array'Address use local_Address; --only for CASE1

How can I write my file2 to have default address ? Or maybe I have to redefine my software design ?

Edit:

In CASE2 I don't want to specify any address.

โŒ
โŒ