Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created October 4, 2018 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewrk/7d58a9bac1b0c28e35b1c3fd75a548d6 to your computer and use it in GitHub Desktop.
Save andrewrk/7d58a9bac1b0c28e35b1c3fd75a548d6 to your computer and use it in GitHub Desktop.
detect if code is executing at compile time in zig (don't do this)
const std = @import("std");
test "detect comptime" {
std.debug.warn("\n");
std.debug.warn("1={}\n", isCompTime());
std.debug.warn("2={}\n", comptime isCompTime());
std.debug.warn("3={}\n", comptime isCompTime());
std.debug.warn("4={}\n", isCompTime());
}
fn isCompTime() bool {
var t: bool = true;
const x = if (t) u7(0) else u8(0);
return @typeOf(x) == u7;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment