1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Raw OS-specific types for the current platform/architecture
13 #![stable(feature = "raw_os", since = "1.1.0")]
15 #[cfg(any(target_os = "android",
16 target_os = "emscripten",
17 all(target_os = "linux", any(target_arch = "aarch64",
19 target_arch = "powerpc",
20 target_arch = "powerpc64",
21 target_arch = "s390x")),
22 all(target_os = "fuchsia", target_arch = "aarch64")))]
23 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
24 #[cfg(not(any(target_os = "android",
25 target_os = "emscripten",
26 all(target_os = "linux", any(target_arch = "aarch64",
28 target_arch = "powerpc",
29 target_arch = "powerpc64",
30 target_arch = "s390x")),
31 all(target_os = "fuchsia", target_arch = "aarch64"))))]
32 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
33 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
34 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
35 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
36 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
37 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
38 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
39 #[cfg(any(target_pointer_width = "32", windows))]
40 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
41 #[cfg(any(target_pointer_width = "32", windows))]
42 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
43 #[cfg(all(target_pointer_width = "64", not(windows)))]
44 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
45 #[cfg(all(target_pointer_width = "64", not(windows)))]
46 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
47 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
48 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
49 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
50 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
52 /// Type used to construct void pointers for use with C.
54 /// This type is only useful as a pointer target. Do not use it as a
55 /// return type for FFI functions which have the `void` return type in
56 /// C. Use the unit type `()` or omit the return type instead.
57 // NB: For LLVM to recognize the void pointer type and by extension
58 // functions like malloc(), we need to have it represented as i8* in
59 // LLVM bitcode. The enum used here ensures this and prevents misuse
60 // of the "raw" type by only having private variants.. We need two
61 // variants, because the compiler complains about the repr attribute
64 #[stable(feature = "raw_os", since = "1.1.0")]
66 #[unstable(feature = "c_void_variant", reason = "should not have to exist",
68 #[doc(hidden)] __variant1,
69 #[unstable(feature = "c_void_variant", reason = "should not have to exist",
71 #[doc(hidden)] __variant2,
75 #[allow(unused_imports)]
83 assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
84 "{} is wrong", stringify!($t));
91 ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong
92 c_longlong c_ulonglong c_float c_double);