Skip to content

translate-c applies bitwise NOT to bool, causing type error in Zig #23987

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

Open
Yeaseen opened this issue May 25, 2025 · 0 comments
Open

translate-c applies bitwise NOT to bool, causing type error in Zig #23987

Yeaseen opened this issue May 25, 2025 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@Yeaseen
Copy link

Yeaseen commented May 25, 2025

Zig Version

0.14.0-dev.3271+bd237bced

Steps to Reproduce and Observed Behavior

C reproducer:

int main() {
    int x = ~((5 >= 3));
    return 0;
}

Zig translate-c translates C expressions involving bitwise NOT (~) on boolean results directly as ~bool, which causes a compile-time error:

runner.zig:58:20: error: unable to perform binary not operation on type 'bool'
    var x: c_int = ~(@as(c_int, 5) >= @as(c_int, 3));

Expected Behavior

translate-c should coerce the boolean to an integer type (e.g., @intFromBool(...)) before applying bitwise operations, to preserve C's implicit promotion rules and avoid Zig type errors. Will close this if it's a dupe.

@Yeaseen Yeaseen added the bug Observed behavior contradicts documented or intended behavior label May 25, 2025
@alexrp alexrp added the translate-c C to Zig source translation feature (@cImport) label May 25, 2025
@alexrp alexrp added this to the 0.15.0 milestone May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

2 participants