-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Casting bool
to pointer
type results in invalid zig
#22964
Comments
I think your cast is not correct, because pub export fn func(arg_b: bool) void {
var b = arg_b;
var x = @as(?*anyopaque, @ptrCast(&b));
_ = &x;
} |
The translated incorrect zig code I provided here was produced by |
The original c code is casting the value of the bool to a pointer so the equivalent zig code would be |
Ok, got it. Even if the C example doesn't make sense. ;-) |
So, this is then the correct translation of the C example: pub export fn func(arg_b: bool) void {
var b = arg_b;
_ = &b;
var x: ?*anyopaque = @as(?*anyopaque, @ptrFromInt(@intFromBool(b)));
_ = &x;
} There is a missing |
True. However, edge cases are lovely to explore. |
Zig Version
0.14.0-dev.3271+bd237bced
Steps to Reproduce and Observed Behavior
Source C code:
translate-c
fails to translate casting ofbool
topointer
Translated Zig Code:
Zig build error:
Expected Behavior
zig translate-c
should correctly handle the cast frombool (u1)
tovoid* (?*anyopaque)
in a safe and Zig-compliant way.The text was updated successfully, but these errors were encountered: