generic type Index is (<>); type Element is private; type Element_Array is array (Index range <>) of aliased Element; Default_Terminator : Element; package Interfaces.C.Pointers is pragma Preelaborate(Pointers);
type Pointer is access all Element;
function Value(Ref : in Pointer; Terminator : in Element := Default_Terminator) return Element_Array;
function Value(Ref : in Pointer; Length : in ptrdiff_t) return Element_Array;
Pointer_Error : exception;
-- C-style Pointer arithmetic
function "+" (Left : in Pointer; Right : in ptrdiff_t) return Pointer; function "+" (Left : in ptrdiff_t; Right : in Pointer) return Pointer; function "-" (Left : in Pointer; Right : in ptrdiff_t) return Pointer; function "-" (Left : in Pointer; Right : in Pointer) return ptrdiff_t;
procedure Increment (Ref : in out Pointer); procedure Decrement (Ref : in out Pointer);
pragma Convention (Intrinsic, "+"); pragma Convention (Intrinsic, "-"); pragma Convention (Intrinsic, Increment); pragma Convention (Intrinsic, Decrement);
function Virtual_Length (Ref : in Pointer; Terminator : in Element := Default_Terminator) return ptrdiff_t;
procedure Copy_Terminated_Array (Source : in Pointer; Target : in Pointer; Limit : in ptrdiff_t := ptrdiff_t'Last; Terminator : in Element := Default_Terminator);
procedure Copy_Array (Source : in Pointer; Target : in Pointer; Length : in ptrdiff_t);
end Interfaces.C.Pointers;
function Value(Ref : in Pointer; Terminator : in Element := Default_Terminator) return Element_Array;
function Value(Ref : in Pointer; Length : in ptrdiff_t) return Element_Array;
procedure Increment (Ref : in out Pointer);
procedure Decrement (Ref : in out Pointer);
function Virtual_Length (Ref : in Pointer; Terminator : in Element := Default_Terminator) return ptrdiff_t;
procedure Copy_Terminated_Array (Source : in Pointer; Target : in Pointer; Limit : in ptrdiff_t := ptrdiff_t'Last; Terminator : in Element := Default_Terminator);
procedure Copy_Array (Source : in Pointer; Target : in Pointer; Length : in ptrdiff_t);
NOTES
Some_Array : Element_Array(0..5) ; Some_Pointer : Pointer := Some_Array(0)'Access;
with Interfaces.C.Pointers; with Interfaces.C.Strings; procedure Test_Pointers is package C renames Interfaces.C; package Char_Ptrs is new C.Pointers (Index => C.size_t, Element => C.char, Element_Array => C.char_array, Default_Terminator => C.nul);
use type Char_Ptrs.Pointer; subtype Char_Star is Char_Ptrs.Pointer;
procedure Strcpy (Target_Ptr, Source_Ptr : Char_Star) is Target_Temp_Ptr : Char_Star := Target_Ptr; Source_Temp_Ptr : Char_Star := Source_Ptr; Element : C.char; begin if Target_Temp_Ptr = null or Source_Temp_Ptr = null then raise C.Strings.Dereference_Error; end if;
loop Element := Source_Temp_Ptr.all; Target_Temp_Ptr.all := Element; exit when Element = C.nul; Char_Ptrs.Increment(Target_Temp_Ptr); Char_Ptrs.Increment(Source_Temp_Ptr); end loop; end Strcpy; begin ... end Test_Pointers;
Go to the first, previous, next, last section, table of contents.