1 -----------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- I N T E R F A C E S . C --
10 -- This specification is adapted from the Ada Reference Manual for use with --
11 -- GNAT. In accordance with the copyright of that document, you can freely --
12 -- copy and modify this specification, provided that if you redistribute a --
13 -- modified version, any changes that you have made are clearly indicated. --
15 ------------------------------------------------------------------------------
17 with System
.Parameters
;
19 package Interfaces
.C
is
22 -- Declaration's based on C's <limits.h>
24 CHAR_BIT
: constant := 8;
25 SCHAR_MIN
: constant := -128;
26 SCHAR_MAX
: constant := 127;
27 UCHAR_MAX
: constant := 255;
29 -- Signed and Unsigned Integers. Note that in GNAT, we have ensured that
30 -- the standard predefined Ada types correspond to the standard C types
32 type int
is new Integer;
33 type short
is new Short_Integer;
34 type long
is range -(2 ** (System
.Parameters
.long_bits
- 1))
35 .. +(2 ** (System
.Parameters
.long_bits
- 1)) - 1;
37 type signed_char
is range SCHAR_MIN
.. SCHAR_MAX
;
38 for signed_char
'Size use CHAR_BIT
;
40 type unsigned
is mod 2 ** int
'Size;
41 type unsigned_short
is mod 2 ** short
'Size;
42 type unsigned_long
is mod 2 ** long
'Size;
44 type unsigned_char
is mod (UCHAR_MAX
+ 1);
45 for unsigned_char
'Size use CHAR_BIT
;
47 subtype plain_char
is unsigned_char
; -- ??? should be parametrized
50 range -(2 ** (Standard
'Address_Size - 1)) ..
51 +(2 ** (Standard
'Address_Size - 1) - 1);
53 type size_t
is mod 2 ** Standard
'Address_Size;
57 type C_float
is new Float;
58 type double
is new Standard
.Long_Float;
59 type long_double
is new Standard
.Long_Long_Float;
61 ----------------------------
62 -- Characters and Strings --
63 ----------------------------
65 type char
is new Character;
67 nul
: constant char
:= char
'First;
69 function To_C
(Item
: Character) return char
;
70 function To_Ada
(Item
: char
) return Character;
72 type char_array
is array (size_t
range <>) of aliased char
;
73 for char_array
'Component_Size use CHAR_BIT
;
75 function Is_Nul_Terminated
(Item
: in char_array
) return Boolean;
79 Append_Nul
: in Boolean := True)
83 (Item
: in char_array
;
84 Trim_Nul
: in Boolean := True)
89 Target
: out char_array
;
91 Append_Nul
: in Boolean := True);
94 (Item
: in char_array
;
97 Trim_Nul
: in Boolean := True);
99 ------------------------------------
100 -- Wide Character and Wide String --
101 ------------------------------------
103 type wchar_t
is new Wide_Character;
104 for wchar_t
'Size use Standard
'Wchar_T_Size;
106 wide_nul
: constant wchar_t
:= wchar_t
'First;
108 function To_C
(Item
: in Wide_Character) return wchar_t
;
109 function To_Ada
(Item
: in wchar_t
) return Wide_Character;
111 type wchar_array
is array (size_t
range <>) of aliased wchar_t
;
113 function Is_Nul_Terminated
(Item
: in wchar_array
) return Boolean;
116 (Item
: in Wide_String;
117 Append_Nul
: in Boolean := True)
121 (Item
: in wchar_array
;
122 Trim_Nul
: in Boolean := True)
126 (Item
: in Wide_String;
127 Target
: out wchar_array
;
129 Append_Nul
: in Boolean := True);
132 (Item
: in wchar_array
;
133 Target
: out Wide_String;
135 Trim_Nul
: in Boolean := True);
137 Terminator_Error
: exception;