Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
Hylo
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
zig source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
zig 0.10.0
zig 0.11.0
zig 0.12.0
zig 0.12.1
zig 0.13.0
zig 0.2.0
zig 0.3.0
zig 0.4.0
zig 0.5.0
zig 0.6.0
zig 0.7.0
zig 0.7.1
zig 0.8.0
zig 0.9.0
zig trunk
Options
Source code
const std = @import("std"); /// The result of a successful parse pub fn Result(comptime T: type) type { return struct { const Value = T; value: T, rest: []const u8, pub fn init(v: T, _rest: []const u8) @This() { return .{ .value = v, .rest = _rest }; } }; } export fn simple_optional(r: *?Result(u8)) u8 { const s = r.* orelse return 11; return s.value; } export fn loop_optional(rs: [*]?Result(u8), len: usize) usize { var sum: usize = 0; for (rs[0..len]) |r| { const s = r orelse continue; sum += s.value; } return sum; }
zig source #2
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
zig 0.10.0
zig 0.11.0
zig 0.12.0
zig 0.12.1
zig 0.13.0
zig 0.2.0
zig 0.3.0
zig 0.4.0
zig 0.5.0
zig 0.6.0
zig 0.7.0
zig 0.7.1
zig 0.8.0
zig 0.9.0
zig trunk
Options
Source code
const std = @import("std"); /// The result of a successful parse pub fn Result(comptime T: type) type { return struct { const Value = T; value: T, rest: []const u8, pub fn init(v: T, _rest: []const u8) @This() { return .{ .value = v, .rest = _rest }; } }; } const Error = error { ParserFailed, OtherError, OutOfMemory }; export fn simple_error(r: *Error!Result(u8)) u8 { const s = r.* catch return 11; return s.value; } export fn loop_error(rs: [*]Error!Result(u8), len: usize) usize { var sum: usize = 0; for (rs[0..len]) |r| { const s = r catch |err| switch (err) { error.ParserFailed => continue, else => return 111, }; sum += s.value; } return sum; }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree