Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test
- import "core:fmt"
- import "core:runtime"
- Bar :: struct(T: typeid) #packed {
- val: T,
- other_data: int,
- }
- Foo :: struct(T: typeid) #packed {
- bar: Bar(T),
- t: u64,
- }
- main :: proc() {
- // T = int
- fmt.printf("type_info_of(Foo(int)) = %v\n", type_info_of(Foo(int))^);
- fmt.printf("type_info_of(Foo(int)).variant = %v\n", type_info_of(Foo(int))^.variant);
- fmt.printf("type_info_of(Foo(int)).variant.base = %v\n", type_info_of(Foo(int))^.variant.(runtime.Type_Info_Named).base^);
- fmt.printf("type_info_of(Foo(int)).variant.base.variant = %v\n", type_info_of(Foo(int))^.variant.(runtime.Type_Info_Named).base^.variant);
- // T = u8
- fmt.printf("type_info_of(Foo(u8 )) = %v\n", type_info_of(Foo(u8))^);
- fmt.printf("type_info_of(Foo(u8 )).variant = %v\n", type_info_of(Foo(u8))^.variant);
- fmt.printf("type_info_of(Foo(u8 )).variant.base = %v\n", type_info_of(Foo(u8))^.variant.(runtime.Type_Info_Named).base^);
- fmt.printf("type_info_of(Foo(u8 )).variant.base.variant = %v\n", type_info_of(Foo(u8))^.variant.(runtime.Type_Info_Named).base^.variant);
- }
- /* Output:
- type_info_of(Foo(int)) = Type_Info{size = 24, align = 1, id = Foo(int), variant = Type_Info_Named{name = Foo(int), base = struct #packed {bar: Bar(T), t: u64}}}
- type_info_of(Foo(int)).variant = Type_Info_Named{name = Foo(int), base = struct #packed {bar: Bar(T), t: u64}}
- type_info_of(Foo(int)).variant.base = Type_Info{size = 24, align = 1, id = struct #packed {bar: Bar(T), t: u64}, variant = Type_Info_Struct{types = [Bar(T), u64], names = [bar, t], offsets = [0, 16], usings = [false, false], is_packed = true, is_raw_union = false, custom_align = false}}
- type_info_of(Foo(int)).variant.base.variant = Type_Info_Struct{types = [Bar(T), u64], names = [bar, t], offsets = [0, 16], usings = [false, false], is_packed = true, is_raw_union = false, custom_align = false}
- ^
- Notice how the offsets differ
- type_info_of(Foo(u8 )) = Type_Info{size = 17, align = 1, id = Foo(u8), variant = Type_Info_Named{name = Foo(u8), base = struct #packed {bar: Bar(T), t: u64}}}
- type_info_of(Foo(u8 )).variant = Type_Info_Named{name = Foo(u8), base = struct #packed {bar: Bar(T), t: u64}}
- type_info_of(Foo(u8 )).variant.base = Type_Info{size = 17, align = 1, id = struct #packed {bar: Bar(T), t: u64}, variant = Type_Info_Struct{types = [Bar(T), u64], names = [bar, t], offsets = [0, 9], usings = [false, false], is_packed = true, is_raw_union = false, custom_align = false}}
- type_info_of(Foo(u8 )).variant.base.variant = Type_Info_Struct{types = [Bar(T), u64], names = [bar, t], offsets = [0, 9], usings = [false, false], is_packed = true, is_raw_union = false, custom_align = false}
- ^
- Different offset
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement