1 -----------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- I N T E R F A C E S . C --
9 -- This specification is adapted from the Ada Reference Manual for use with --
10 -- GNAT. In accordance with the copyright of that document, you can freely --
11 -- copy and modify this specification, provided that if you redistribute a --
12 -- modified version, any changes that you have made are clearly indicated. --
14 ------------------------------------------------------------------------------
16 with System.Parameters;
18 package Interfaces.C is
21 -- Declaration's based on C's <limits.h>
23 CHAR_BIT : constant := 8;
24 SCHAR_MIN : constant := -128;
25 SCHAR_MAX : constant := 127;
26 UCHAR_MAX : constant := 255;
28 -- Signed and Unsigned Integers. Note that in GNAT, we have ensured that
29 -- the standard predefined Ada types correspond to the standard C types
31 type int is new Integer;
32 type short is new Short_Integer;
33 type long is range -(2 ** (System.Parameters.long_bits - 1))
34 .. +(2 ** (System.Parameters.long_bits - 1)) - 1;
36 type signed_char is range SCHAR_MIN .. SCHAR_MAX;
37 for signed_char'Size use CHAR_BIT;
39 type unsigned is mod 2 ** int'Size;
40 type unsigned_short is mod 2 ** short'Size;
41 type unsigned_long is mod 2 ** long'Size;
43 type unsigned_char is mod (UCHAR_MAX + 1);
44 for unsigned_char'Size use CHAR_BIT;
46 subtype plain_char is unsigned_char; -- ??? should be parametrized
49 range -(2 ** (Standard'Address_Size - 1)) ..
50 +(2 ** (Standard'Address_Size - 1) - 1);
52 type size_t is mod 2 ** Standard'Address_Size;
56 type C_float is new Float;
57 type double is new Standard.Long_Float;
58 type long_double is new Standard.Long_Long_Float;
60 ----------------------------
61 -- Characters and Strings --
62 ----------------------------
64 type char is new Character;
66 nul : constant char := char'First;
68 function To_C (Item : Character) return char;
69 function To_Ada (Item : char) return Character;
71 type char_array is array (size_t range <>) of aliased char;
72 for char_array'Component_Size use CHAR_BIT;
74 function Is_Nul_Terminated (Item : in char_array) return Boolean;
78 Append_Nul : in Boolean := True)
82 (Item : in char_array;
83 Trim_Nul : in Boolean := True)
88 Target : out char_array;
90 Append_Nul : in Boolean := True);
93 (Item : in char_array;
96 Trim_Nul : in Boolean := True);
98 ------------------------------------
99 -- Wide Character and Wide String --
100 ------------------------------------
102 type wchar_t is new Wide_Character;
103 for wchar_t'Size use Standard'Wchar_T_Size;
105 wide_nul : constant wchar_t := wchar_t'First;
107 function To_C (Item : in Wide_Character) return wchar_t;
108 function To_Ada (Item : in wchar_t) return Wide_Character;
110 type wchar_array is array (size_t range <>) of aliased wchar_t;
112 function Is_Nul_Terminated (Item : in wchar_array) return Boolean;
115 (Item : in Wide_String;
116 Append_Nul : in Boolean := True)
120 (Item : in wchar_array;
121 Trim_Nul : in Boolean := True)
125 (Item : in Wide_String;
126 Target : out wchar_array;
128 Append_Nul : in Boolean := True);
131 (Item : in wchar_array;
132 Target : out Wide_String;
134 Trim_Nul : in Boolean := True);
136 Terminator_Error : exception;