Replies: 2 comments 6 replies
-
空洞是啥意思呀?padding? |
Beta Was this translation helpful? Give feedback.
4 replies
-
我找到方法了,zig的类型系统果然强大 const A = struct {
a: u64,
b: u32,
};
comptime {
if (hasPadding(A)) {
@compileError("has padding!");
}
}
fn hasPadding(comptime T: type) bool {
const struct_size = @sizeOf(T);
var total_size = 0;
switch (@typeInfo(T)) {
.Struct => |info| {
for (info.fields) |field| {
total_size += @sizeOf(field.type);
}
},
else => @compileError("not support yet"),
}
return struct_size != total_size;
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
比如我定义了:
这个结构体里有个空洞。标准库里有这样的函数吗?
Beta Was this translation helpful? Give feedback.
All reactions