1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 //! bindgen test for .h file
17 #![allow(clippy::approx_constant)]
18 #![allow(clippy::eq_op)]
19 mod c_ffi {
20 #![allow(dead_code)]
21 #![allow(non_upper_case_globals)]
22 #![allow(non_camel_case_types)]
23 include!(env!("BINDGEN_RS_FILE"));
24 }
25
bindgen_test_layout_foo()26 fn bindgen_test_layout_foo() {
27 const UNINIT: ::std::mem::MaybeUninit<c_ffi::Foo2> = ::std::mem::MaybeUninit::uninit();
28 let ptr = UNINIT.as_ptr();
29 println!(
30 "The mem size of c_ffi::Foo2 is {} usize",
31 ::std::mem::size_of::<c_ffi::Foo2>()
32 );
33 println!(
34 "The align_of size of c_ffi::Foo2 is {} usize",
35 ::std::mem::align_of::<c_ffi::Foo2>()
36 );
37 println!(
38 "The ptr addr of!((*ptr).member) as usize - ptr as usize is {} usize",
39 unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }
40 );
41 }
42 impl Default for c_ffi::Foo2 {
default() -> Self43 fn default() -> Self {
44 let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
45 unsafe {
46 ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
47 s.assume_init()
48 }
49 }
50 }
51
52 /// fn main()
main()53 fn main() {
54 bindgen_test_layout_foo();
55 }
56