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
.
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:
Explained here: Memory Management with Ada 2012.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With