[nix-shell:~/dev/zig/build]$ cat test.zig const Point = struct { x: i32, y: i32 }; export fn main() c_int { var p: Point = .{ .x = 12, .y = 24, }; return p.y - p.x - p.x; } [nix-shell:~/dev/zig/build]$ ./zig-cache/bin/zig build-exe test.zig --verbose-ir -ofmt=c ZIR fn_type main %0 = block({ %1 = fn_type([], @Ref.c_int_type) node_offset:3:8 %2 = break_inline(%0, %1) }) node_offset:3:8 // end ZIR fn_type main ZIR fn_body main %0 = block({ %1 = dbg_stmt_node() node_offset:4:5 %2 = decl_val(Point) node_offset:4:12 %3 = as_node(@Ref.type_type, %2) node_offset:4:12 %4 = alloc_mut(%3) node_offset:4:5 %5 = field_ptr(%4, "x") node_offset:5:14 %6 = int(12) %7 = store_node(%5, %6) node_offset:5:14 %8 = field_ptr(%4, "y") node_offset:6:14 %9 = int(24) %10 = store_node(%8, %9) node_offset:6:14 %11 = validate_struct_init_ptr({ %5 = field_ptr(%4, "x") node_offset:5:14 %8 = field_ptr(%4, "y") node_offset:6:14 }) node_offset:4:21 %12 = dbg_stmt_node() node_offset:8:5 %13 = ret_type() node_offset:8:5 %14 = field_val(%4, "y") node_offset:8:13 %15 = field_val(%4, "x") node_offset:8:19 %16 = sub(%14, %15) node_offset:8:16 %17 = field_val(%4, "x") node_offset:8:25 %18 = sub(%16, %17) node_offset:8:22 %19 = as_node(%13, %18) node_offset:8:22 %20 = ret_node(%19) node_offset:8:5 %21 = ret_coerce(@Ref.void_value) token_offset:9:1 }) node_offset:3:8 // end ZIR fn_body main ZIR var_init Point %0 = block({ %1 = struct_decl({ x: @Ref.i32_type, y: @Ref.i32_type, }) node_offset:1:15 %2 = break_inline(%0, %1) }) node_offset:1:1 // end ZIR var_init Point warning(sema): TODO implement zirValidateStructInitPtr (compile errors for missing/dupe fields) Module.Function(name=main): @0: i32 = 12; @1: i32 = 24; %0: void = dbg_stmt() %1: *(struct) = alloc() %2: *i32 = struct_field_ptr(%10) %3: void = store(%2, @0) %4: *i32 = struct_field_ptr(%11) %5: void = store(%4, @1) %6: void = dbg_stmt() %7: *i32 = struct_field_ptr(%11) %8: i32 = load(%7) %9: *i32 = struct_field_ptr(%10) %10: i32 = load(%9) %11: i32 = sub(%8, %10) %12: *i32 = struct_field_ptr(%10) %13: i32 = load(%12) %14: i32 = sub(%11, %13) %15: c_int = intcast(%14) %16: noreturn = ret(%15) warning(Type): TODO implement Type.onePossibleValue for structs warning(Type): TODO implement Type.onePossibleValue for structs warning(Type): TODO implement Type.onePossibleValue for structs warning(Type): TODO implement Type.onePossibleValue for structs warning(Type): TODO implement Type.onePossibleValue for structs [nix-shell:~/dev/zig/build]$ cat test.c #if __STDC_VERSION__ >= 199901L #include #else #define bool unsigned char #define true 1 #define false 0 #endif #if __STDC_VERSION__ >= 201112L #define zig_noreturn _Noreturn #elif __GNUC__ #define zig_noreturn __attribute__ ((noreturn)) #elif _MSC_VER #define zig_noreturn __declspec(noreturn) #else #define zig_noreturn #endif #if defined(__GNUC__) #define zig_unreachable() __builtin_unreachable() #else #define zig_unreachable() #endif #if __STDC_VERSION__ >= 199901L #define ZIG_RESTRICT restrict #elif defined(__GNUC__) #define ZIG_RESTRICT __restrict #else #define ZIG_RESTRICT #endif #ifdef __cplusplus #define ZIG_EXTERN_C extern "C" #else #define ZIG_EXTERN_C #endif #if defined(_MSC_VER) #define zig_breakpoint() __debugbreak() #elif defined(__MINGW32__) || defined(__MINGW64__) #define zig_breakpoint() __debugbreak() #elif defined(__clang__) #define zig_breakpoint() __builtin_debugtrap() #elif defined(__GNUC__) #define zig_breakpoint() __builtin_trap() #elif defined(__i386__) || defined(__x86_64__) #define zig_breakpoint() __asm__ volatile("int $0x03"); #else #define zig_breakpoint() raise(SIGTRAP) #endif #include #include #define int128_t __int128 #define uint128_t unsigned __int128 ZIG_EXTERN_C void *memcpy (void *ZIG_RESTRICT, const void *ZIG_RESTRICT, size_t); typedef struct { int32_t x; int32_t y; } zig_S_Point; ZIG_EXTERN_C int main(void); int main(void) { zig_S_Point t0; int32_t * const t1 = &t0.x; *t1 = 12; int32_t * const t2 = &t0.y; *t2 = 24; int32_t * const t3 = &t0.y; int32_t const t4 = *t3; int32_t * const t5 = &t0.x; int32_t const t6 = *t5; int32_t const t7 = t4 - t6; int32_t * const t8 = &t0.x; int32_t const t9 = *t8; int32_t const t10 = t7 - t9; int const t11 = (int)t10; return t11; } [nix-shell:~/dev/zig/build]$ ./zig run test.c -lc [nix-shell:~/dev/zig/build]$ echo $? 0