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------------------------------------------------------------------------------
37
38with System.Parameters;
39
40package Interfaces.C is
41pragma Pure (C);
42
43   --  Declaration's based on C's <limits.h>
44
45   CHAR_BIT  : constant := 8;
46   SCHAR_MIN : constant := -128;
47   SCHAR_MAX : constant := 127;
48   UCHAR_MAX : constant := 255;
49
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
52
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;
57
58   type signed_char is range SCHAR_MIN .. SCHAR_MAX;
59   for signed_char'Size use CHAR_BIT;
60
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;
64
65   type unsigned_char is mod (UCHAR_MAX + 1);
66   for unsigned_char'Size use CHAR_BIT;
67
68   subtype plain_char is unsigned_char; -- ??? should be parametrized
69
70   type ptrdiff_t is
71     range -(2 ** (Standard'Address_Size - 1)) ..
72           +(2 ** (Standard'Address_Size - 1) - 1);
73
74   type size_t is mod 2 ** Standard'Address_Size;
75
76   --  Floating-Point
77
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;
81
82   ----------------------------
83   -- Characters and Strings --
84   ----------------------------
85
86   type char is new Character;
87
88   nul : constant char := char'First;
89
90   function To_C   (Item : Character) return char;
91   function To_Ada (Item : char)      return Character;
92
93   type char_array is array (size_t range <>) of aliased char;
94   for char_array'Component_Size use CHAR_BIT;
95
96   function Is_Nul_Terminated (Item : in char_array) return Boolean;
97
98   function To_C
99     (Item       : in String;
100      Append_Nul : in Boolean := True)
101      return       char_array;
102
103   function To_Ada
104     (Item     : in char_array;
105      Trim_Nul : in Boolean := True)
106      return     String;
107
108   procedure To_C
109     (Item       : in String;
110      Target     : out char_array;
111      Count      : out size_t;
112      Append_Nul : in Boolean := True);
113
114   procedure To_Ada
115     (Item     : in char_array;
116      Target   : out String;
117      Count    : out Natural;
118      Trim_Nul : in Boolean := True);
119
120   ------------------------------------
121   -- Wide Character and Wide String --
122   ------------------------------------
123
124   type wchar_t is new Wide_Character;
125   for wchar_t'Size use Standard'Wchar_T_Size;
126
127   wide_nul : constant wchar_t := wchar_t'First;
128
129   function To_C   (Item : in Wide_Character) return wchar_t;
130   function To_Ada (Item : in wchar_t)        return Wide_Character;
131
132   type wchar_array is array (size_t range <>) of aliased wchar_t;
133
134   function Is_Nul_Terminated (Item : in wchar_array) return Boolean;
135
136   function To_C
137     (Item       : in Wide_String;
138      Append_Nul : in Boolean := True)
139      return       wchar_array;
140
141   function To_Ada
142     (Item     : in wchar_array;
143      Trim_Nul : in Boolean := True)
144      return     Wide_String;
145
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);
151
152   procedure To_Ada
153     (Item     : in wchar_array;
154      Target   : out Wide_String;
155      Count    : out Natural;
156      Trim_Nul : in Boolean := True);
157
158   Terminator_Error : exception;
159
160private
161   --  No private declarations required
162end Interfaces.C;
163