1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- I N T E R F A C E S . C --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 2, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, USA. --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
36 ------------------------------------------------------------------------------
38 with System
.Parameters
;
40 package Interfaces
.C
is
43 -- Declaration's based on C's <limits.h>
45 CHAR_BIT
: constant := 8;
46 SCHAR_MIN
: constant := -128;
47 SCHAR_MAX
: constant := 127;
48 UCHAR_MAX
: constant := 255;
50 -- Signed and Unsigned Integers. Note that in GNAT, we have ensured that
51 -- the standard predefined Ada types correspond to the standard C types
53 type int
is new Integer;
54 type short
is new Short_Integer;
55 type long
is range -(2 ** (System
.Parameters
.long_bits
- 1))
56 .. +(2 ** (System
.Parameters
.long_bits
- 1)) - 1;
58 type signed_char
is range SCHAR_MIN
.. SCHAR_MAX
;
59 for signed_char
'Size use CHAR_BIT
;
61 type unsigned
is mod 2 ** int
'Size;
62 type unsigned_short
is mod 2 ** short
'Size;
63 type unsigned_long
is mod 2 ** long
'Size;
65 type unsigned_char
is mod (UCHAR_MAX
+ 1);
66 for unsigned_char
'Size use CHAR_BIT
;
68 subtype plain_char
is unsigned_char
; -- ??? should be parametrized
71 range -(2 ** (Standard
'Address_Size - 1)) ..
72 +(2 ** (Standard
'Address_Size - 1) - 1);
74 type size_t
is mod 2 ** Standard
'Address_Size;
78 type C_float
is new Float;
79 type double
is new Standard
.Long_Float;
80 type long_double
is new Standard
.Long_Long_Float;
82 ----------------------------
83 -- Characters and Strings --
84 ----------------------------
86 type char
is new Character;
88 nul
: constant char
:= char
'First;
90 function To_C
(Item
: Character) return char
;
91 function To_Ada
(Item
: char
) return Character;
93 type char_array
is array (size_t
range <>) of aliased char
;
94 for char_array
'Component_Size use CHAR_BIT
;
96 function Is_Nul_Terminated
(Item
: in char_array
) return Boolean;
100 Append_Nul
: in Boolean := True)
104 (Item
: in char_array
;
105 Trim_Nul
: in Boolean := True)
110 Target
: out char_array
;
112 Append_Nul
: in Boolean := True);
115 (Item
: in char_array
;
118 Trim_Nul
: in Boolean := True);
120 ------------------------------------
121 -- Wide Character and Wide String --
122 ------------------------------------
124 type wchar_t
is new Wide_Character;
125 for wchar_t
'Size use Standard
'Wchar_T_Size;
127 wide_nul
: constant wchar_t
:= wchar_t
'First;
129 function To_C
(Item
: in Wide_Character) return wchar_t
;
130 function To_Ada
(Item
: in wchar_t
) return Wide_Character;
132 type wchar_array
is array (size_t
range <>) of aliased wchar_t
;
134 function Is_Nul_Terminated
(Item
: in wchar_array
) return Boolean;
137 (Item
: in Wide_String;
138 Append_Nul
: in Boolean := True)
142 (Item
: in wchar_array
;
143 Trim_Nul
: in Boolean := True)
147 (Item
: in Wide_String;
148 Target
: out wchar_array
;
150 Append_Nul
: in Boolean := True);
153 (Item
: in wchar_array
;
154 Target
: out Wide_String;
156 Trim_Nul
: in Boolean := True);
158 Terminator_Error
: exception;
161 -- No private declarations required