]> git.lizzy.rs Git - rust.git/blob - src/libcore/ctypes.rs
d26b183a2f38d2a7badf196bb345df36a6e646d0
[rust.git] / src / libcore / ctypes.rs
1 /*
2 Module: ctypes
3
4 Definitions useful for C interop
5 */
6
7 /*
8 FIXME: Add a test that uses some native code to verify these sizes,
9 which are not obviously correct for all potential platforms.
10 */
11
12 // PORT adapt to architecture
13
14 /*
15 Type: c_int
16
17 A signed integer with the same size as a C `int`
18 */
19 type c_int = i32;
20
21 /*
22 Type: c_uint
23
24 An unsigned integer with the same size as a C `unsigned int`
25 */
26 type c_uint = u32;
27
28 /*
29 Type: long
30
31 A signed integer with the same size as a C `long`
32 */
33 type long = int;
34
35 /*
36 Type: unsigned
37
38 An unsigned integer with the same size as a C `unsigned int`
39 */
40 type unsigned = u32;
41
42 /*
43 Type: ulong
44
45 An unsigned integer with the same size as a C `unsigned long`
46 */
47 type ulong = uint;
48
49 /*
50 Type: intptr_t
51
52 A signed integer with the same size as a pointer. This is
53 guaranteed to always be the same type as a Rust `int`
54 */
55 type intptr_t = uint; // FIXME: int
56
57 /*
58 Type: uintptr_t
59
60 An unsigned integer with the same size as a pointer. This is
61 guaranteed to always be the same type as a Rust `uint`.
62 */
63 type uintptr_t = uint;
64 type uint32_t = u32;
65
66 /*
67 Type: void
68
69 A type, a pointer to which can be used as C `void *`
70
71 Note that this does not directly correspond to the C `void` type,
72 which is an incomplete type. Using pointers to this type
73 when interoperating with C void pointers can help in documentation.
74 */
75 type void = int;
76
77 /*
78 Type: c_float
79
80 A float value with the same size as a C `float`
81 */
82 type c_float = f32;
83
84 /*
85 Type: c_float
86
87 A float value with the same size as a C `double`
88 */
89 type c_double = f64;
90
91 /*
92 Type: size_t
93
94 An unsigned integer corresponding to the C `size_t`
95 */
96 type size_t = uint;
97
98 /*
99 Type: ssize_t
100
101 A signed integer correpsonding to the C `ssize_t`
102 */
103 type ssize_t = int;
104
105 /*
106 Type: off_t
107
108 An unsigned integer corresponding to the C `off_t`
109 */
110 type off_t = uint;
111
112 /*
113 Type: fd_t
114
115 A type that can be used for C file descriptors
116 */
117 type fd_t = i32;      // not actually a C type, but should be.
118
119 /*
120 Type: pid_t
121
122 A type for representing process ID's, corresponding to C `pid_t`
123 */
124 type pid_t = i32;
125
126 // enum is implementation-defined, but is 32-bits in practice
127 /*
128 Type: enum
129
130 An unsigned integer with the same size as a C enum
131 */
132 type enum = u32;
133