Created
October 4, 2018 04:56
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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