2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / ada / i-c.ads
blob9b97258c181bf231b103cb5f2d8d5c23992ce62e
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-2003 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 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
70 type ptrdiff_t is
71 range -(2 ** (Standard'Address_Size - 1)) ..
72 +(2 ** (Standard'Address_Size - 1) - 1);
74 type size_t is mod 2 ** Standard'Address_Size;
76 -- Floating-Point
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;
98 function To_C
99 (Item : in String;
100 Append_Nul : in Boolean := True)
101 return char_array;
103 function To_Ada
104 (Item : in char_array;
105 Trim_Nul : in Boolean := True)
106 return String;
108 procedure To_C
109 (Item : in String;
110 Target : out char_array;
111 Count : out size_t;
112 Append_Nul : in Boolean := True);
114 procedure To_Ada
115 (Item : in char_array;
116 Target : out String;
117 Count : out Natural;
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;
136 function To_C
137 (Item : in Wide_String;
138 Append_Nul : in Boolean := True)
139 return wchar_array;
141 function To_Ada
142 (Item : in wchar_array;
143 Trim_Nul : in Boolean := True)
144 return Wide_String;
146 procedure To_C
147 (Item : in Wide_String;
148 Target : out wchar_array;
149 Count : out size_t;
150 Append_Nul : in Boolean := True);
152 procedure To_Ada
153 (Item : in wchar_array;
154 Target : out Wide_String;
155 Count : out Natural;
156 Trim_Nul : in Boolean := True);
158 Terminator_Error : exception;
160 private
161 -- No private declarations required
162 end Interfaces.C;