mirror of
https://github.com/ziglang/zig.git
synced 2025-12-10 16:23:07 +00:00
Instead use the standarized option for communicating the zig compiler backend at comptime, which is `zig_backend`. This was introduced in commit 1c24ef0d0b09a12a1fe98056f2fc04de78a82df3.
19 lines
541 B
Zig
19 lines
541 B
Zig
const std = @import("std");
|
|
|
|
test "lazy sizeof comparison with zero" {
|
|
const Empty = struct {};
|
|
const T = *Empty;
|
|
|
|
try std.testing.expect(hasNoBits(T));
|
|
}
|
|
|
|
fn hasNoBits(comptime T: type) bool {
|
|
if (@import("builtin").zig_backend != .stage1) {
|
|
// It is an accepted proposal to make `@sizeOf` for pointers independent
|
|
// of whether the element type is zero bits.
|
|
// This language change has not been implemented in stage1.
|
|
return @sizeOf(T) == @sizeOf(*i32);
|
|
}
|
|
return @sizeOf(T) == 0;
|
|
}
|