Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

General Access type Ada

I am still confused on how all keyword works in a general access type

what's the difference between:

type int_access is access all Integer; to type int_access is access Integer;

for example:

type int_ptr is access all Integer;

Var : aliased Integer := 1;

Ptr : int_ptr := Var'Access;

the code works fine but if I remove the all keyword it gives an error that result must be general access type and I must add all.

like image 350
Amben Uchiha Avatar asked May 15 '21 13:05

Amben Uchiha


Video Answer


2 Answers

Pool-specific access types -- those without the "all" -- can be used only for objects allocated in the heap (or in some user-defined storage pool) with the "new" keyword.

So this is OK:

type Int_Ptr is access Integer;
Prt: Int_Ptr := new Integer;

General access types -- those with the "all" -- can be used both for heap-allocated objects, and for any other object that is marked "aliased". So this is also OK:

type Int_Ptr is access all Integer;
Prt: Int_Ptr := new Integer;

So the rules, in brief, are:

  • without "all": only objects allocated with "new"
  • with "all": in addition, any object marked "aliased".
like image 113
Niklas Holsti Avatar answered Oct 18 '22 10:10

Niklas Holsti


Explained here: Memory Management with Ada 2012.

like image 26
Shark8 Avatar answered Oct 18 '22 10:10

Shark8