PR target/16201
[official-gcc.git] / gcc / ada / i-c.ads
blobbcd77a897e44d61a6659e092dfa6a1038bd932f3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- I N T E R F A C E S . C --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
10 -- --
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. --
14 -- --
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. --
25 -- --
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. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 with System.Parameters;
40 package Interfaces.C is
41 pragma Pure (C);
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 -- Note: the Integer qualifications used in the declaration of type long
54 -- avoid ambiguities when compiling in the presence of s-auxdec.ads and
55 -- a non-private system.address type.
57 type int is new Integer;
58 type short is new Short_Integer;
59 type long is range -(2 ** (System.Parameters.long_bits - Integer'(1)))
60 .. +(2 ** (System.Parameters.long_bits - Integer'(1))) - 1;
62 type signed_char is range SCHAR_MIN .. SCHAR_MAX;
63 for signed_char'Size use CHAR_BIT;
65 type unsigned is mod 2 ** int'Size;
66 type unsigned_short is mod 2 ** short'Size;
67 type unsigned_long is mod 2 ** long'Size;
69 type unsigned_char is mod (UCHAR_MAX + 1);
70 for unsigned_char'Size use CHAR_BIT;
72 subtype plain_char is unsigned_char; -- ??? should be parametrized
74 -- Note: the Integer qualifications used in the declaration of ptrdiff_t
75 -- avoid ambiguities when compiling in the presence of s-auxdec.ads and
76 -- a non-private system.address type.
78 type ptrdiff_t is
79 range -(2 ** (Standard'Address_Size - Integer'(1))) ..
80 +(2 ** (Standard'Address_Size - Integer'(1)) - 1);
82 type size_t is mod 2 ** Standard'Address_Size;
84 -- Floating-Point
86 type C_float is new Float;
87 type double is new Standard.Long_Float;
88 type long_double is new Standard.Long_Long_Float;
90 ----------------------------
91 -- Characters and Strings --
92 ----------------------------
94 type char is new Character;
96 nul : constant char := char'First;
98 function To_C (Item : Character) return char;
99 function To_Ada (Item : char) return Character;
101 type char_array is array (size_t range <>) of aliased char;
102 for char_array'Component_Size use CHAR_BIT;
104 function Is_Nul_Terminated (Item : in char_array) return Boolean;
106 function To_C
107 (Item : in String;
108 Append_Nul : in Boolean := True)
109 return char_array;
111 function To_Ada
112 (Item : in char_array;
113 Trim_Nul : in Boolean := True)
114 return String;
116 procedure To_C
117 (Item : in String;
118 Target : out char_array;
119 Count : out size_t;
120 Append_Nul : in Boolean := True);
122 procedure To_Ada
123 (Item : in char_array;
124 Target : out String;
125 Count : out Natural;
126 Trim_Nul : in Boolean := True);
128 ------------------------------------
129 -- Wide Character and Wide String --
130 ------------------------------------
132 type wchar_t is new Wide_Character;
133 for wchar_t'Size use Standard'Wchar_T_Size;
135 wide_nul : constant wchar_t := wchar_t'First;
137 function To_C (Item : in Wide_Character) return wchar_t;
138 function To_Ada (Item : in wchar_t) return Wide_Character;
140 type wchar_array is array (size_t range <>) of aliased wchar_t;
142 function Is_Nul_Terminated (Item : in wchar_array) return Boolean;
144 function To_C
145 (Item : in Wide_String;
146 Append_Nul : in Boolean := True)
147 return wchar_array;
149 function To_Ada
150 (Item : in wchar_array;
151 Trim_Nul : in Boolean := True)
152 return Wide_String;
154 procedure To_C
155 (Item : in Wide_String;
156 Target : out wchar_array;
157 Count : out size_t;
158 Append_Nul : in Boolean := True);
160 procedure To_Ada
161 (Item : in wchar_array;
162 Target : out Wide_String;
163 Count : out Natural;
164 Trim_Nul : in Boolean := True);
166 Terminator_Error : exception;
168 private
169 -- No private declarations required
170 end Interfaces.C;