Skip to content
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

stage2: translate-c macro with division results in compile error #13162

Closed
mitchellh opened this issue Oct 14, 2022 · 0 comments · Fixed by #13329
Closed

stage2: translate-c macro with division results in compile error #13162

mitchellh opened this issue Oct 14, 2022 · 0 comments · Fixed by #13329
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@mitchellh
Copy link
Contributor

mitchellh commented Oct 14, 2022

Zig Version

0.10.0-dev.4324+c23b3e6fd

Steps to Reproduce

translate-c the following and use the resulting function

#define GLAD_VERSION_MAJOR(version) (version / 10000)
c.GLAD_VERSION_MAJOR(@as(c_int, 20000));

Expected Behavior

Works.

Actual Behavior

Error:

cimport.zig:1362:68: error: division with 'c_int' and 'c_int': signed integers must use @divTrunc, @divFloor, or @divExact
pub inline fn GLAD_VERSION_MAJOR(version: anytype) @TypeOf(version / @as(c_int, 10000)) {

Full translation:

pub inline fn GLAD_VERSION_MAJOR(version: anytype) @TypeOf(version / @as(c_int, 10000)) {
    return version / @as(c_int, 10000);
}
@mitchellh mitchellh added the bug Observed behavior contradicts documented or intended behavior label Oct 14, 2022
@mitchellh mitchellh reopened this Oct 14, 2022
@Vexu Vexu added the translate-c C to Zig source translation feature (@cImport) label Oct 14, 2022
@Vexu Vexu added this to the 0.11.0 milestone Oct 14, 2022
ehaas added a commit to ehaas/zig that referenced this issue Oct 28, 2022
Perform C-style arithmetic conversions on operands to division operator
in macros

Closes ziglang#13162
ehaas added a commit to ehaas/zig that referenced this issue Oct 28, 2022
Perform C-style arithmetic conversions on operands to division operator
in macros

Closes ziglang#13162
andrewrk pushed a commit that referenced this issue Oct 28, 2022
Perform C-style arithmetic conversions on operands to division operator
in macros

Closes #13162
@andrewrk andrewrk modified the milestones: 0.11.0, 0.10.0 Oct 28, 2022
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

Successfully merging a pull request may close this issue.

3 participants