home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / i-c.ads < prev    next >
Text File  |  2000-07-19  |  5KB  |  142 lines

  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. --                            $Revision: 1.17 $                             --
  10. --                                                                          --
  11. -- This specification is adapted from the Ada Reference Manual for use with --
  12. -- GNAT.  In accordance with the copyright of that document, you can freely --
  13. -- copy and modify this specification,  provided that if you redistribute a --
  14. -- modified version,  any changes that you have made are clearly indicated. --
  15. --                                                                          --
  16. ------------------------------------------------------------------------------
  17.  
  18. with System.Parameters;
  19.  
  20. package Interfaces.C is
  21. pragma Pure (C);
  22.  
  23.    lbits1 : constant := System.Parameters.long_bits - 1;
  24.  
  25.    --  Declaration's based on C's <limits.h>
  26.  
  27.    CHAR_BIT  : constant := 8;
  28.    SCHAR_MIN : constant := -128;
  29.    SCHAR_MAX : constant := 127;
  30.    UCHAR_MAX : constant := 255;
  31.  
  32.    --  Signed and Unsigned Integers. Note that in GNAT, we have ensured that
  33.    --  the standard predefined Ada types correspond to the standard C types
  34.  
  35.    type int   is new Integer;
  36.    type short is new Short_Integer;
  37.    type long  is range -(2 ** lbits1) .. +(2 ** lbits1) - 1;
  38.  
  39.    type signed_char is range SCHAR_MIN .. SCHAR_MAX;
  40.    for signed_char'Size use CHAR_BIT;
  41.  
  42.    type unsigned       is mod 2 ** int'Size;
  43.    type unsigned_short is mod 2 ** short'Size;
  44.    type unsigned_long  is mod 2 ** long'Size;
  45.  
  46.    type unsigned_char is mod (UCHAR_MAX + 1);
  47.    for unsigned_char'Size use CHAR_BIT;
  48.  
  49.    subtype plain_char is unsigned_char; -- ??? should be parametrized
  50.  
  51.    type ptrdiff_t is
  52.      range -(2 ** (Standard'Address_Size - 1)) ..
  53.            +(2 ** (Standard'Address_Size - 1) - 1);
  54.  
  55.    type size_t is mod 2 ** Standard'Address_Size;
  56.  
  57.    --  Floating-Point
  58.  
  59.    type C_float     is new Float;
  60.    type double      is new Standard.Long_Float;
  61.    type long_double is new Standard.Long_Long_Float;
  62.  
  63.    ----------------------------
  64.    -- Characters and Strings --
  65.    ----------------------------
  66.  
  67.    type char is new Character;
  68.  
  69.    nul : constant char := char'First;
  70.  
  71.    function To_C   (Item : Character) return char;
  72.    function To_Ada (Item : char)      return Character;
  73.  
  74.    type char_array is array (size_t range <>) of aliased char;
  75.    for char_array'Component_Size use CHAR_BIT;
  76.  
  77.    function Is_Nul_Terminated (Item : in char_array) return Boolean;
  78.  
  79.    function To_C
  80.      (Item       : in String;
  81.       Append_Nul : in Boolean := True)
  82.       return       char_array;
  83.  
  84.    function To_Ada
  85.      (Item     : in char_array;
  86.       Trim_Nul : in Boolean := True)
  87.       return     String;
  88.  
  89.    procedure To_C
  90.      (Item       : in String;
  91.       Target     : out char_array;
  92.       Count      : out size_t;
  93.       Append_Nul : in Boolean := True);
  94.  
  95.    procedure To_Ada
  96.      (Item     : in char_array;
  97.       Target   : out String;
  98.       Count    : out Natural;
  99.       Trim_Nul : in Boolean := True);
  100.  
  101.    ------------------------------------
  102.    -- Wide Character and Wide String --
  103.    ------------------------------------
  104.  
  105.    type wchar_t is new Wide_Character;
  106.    for wchar_t'Size use System.Parameters.wchar_t_bits;
  107.  
  108.    wide_nul : constant wchar_t := wchar_t'First;
  109.  
  110.    function To_C   (Item : in Wide_Character) return wchar_t;
  111.    function To_Ada (Item : in wchar_t)        return Wide_Character;
  112.  
  113.    type wchar_array is array (size_t range <>) of aliased wchar_t;
  114.  
  115.    function Is_Nul_Terminated (Item : in wchar_array) return Boolean;
  116.  
  117.    function To_C
  118.      (Item       : in Wide_String;
  119.       Append_Nul : in Boolean := True)
  120.       return       wchar_array;
  121.  
  122.    function To_Ada
  123.      (Item     : in wchar_array;
  124.       Trim_Nul : in Boolean := True)
  125.       return     Wide_String;
  126.  
  127.    procedure To_C
  128.      (Item       : in Wide_String;
  129.       Target     : out wchar_array;
  130.       Count      : out size_t;
  131.       Append_Nul : in Boolean := True);
  132.  
  133.    procedure To_Ada
  134.      (Item     : in wchar_array;
  135.       Target   : out Wide_String;
  136.       Count    : out Natural;
  137.       Trim_Nul : in Boolean := True);
  138.  
  139.    Terminator_Error : exception;
  140.  
  141. end Interfaces.C;
  142.