zig icon indicating copy to clipboard operation
zig copied to clipboard

translate-c has issues with int signedness in "windows.h"

Open ontes opened this issue 2 years ago • 2 comments

Zig Version

0.9.1

Steps to Reproduce

Import "windows.h" and try to use LOWORD and HIWORD macros.

Expected Behavior

Works.

Actual Behavior

error: expected type 'c_ulonglong', found 'c_int'

The translated code looks like this:

@import("std").zig.c_translation.cast(WORD, (@import("std").zig.c_translation.cast(DWORD_PTR, l) >> @as(c_int, 16)) & @import("std").zig.c_translation.promoteIntLiteral(c_int, 0xffff, .hexadecimal))

Removing the promoteIntLiteral at the end fixes the issue. 0xffff can be casted to c_ulonglong automaticaly, but produces an error when it is promoted to c_int before that.

ontes avatar Apr 09 '22 09:04 ontes

Does the suggested fix in the comment here: https://github.com/ziglang/zig/issues/10793#issuecomment-1030504654= fix the issue?

ehaas avatar Apr 10 '22 02:04 ehaas

Does the suggested fix in the comment here: #10793 (comment) fix the issue?

No, still the same. I don't think that the issue is in the function promoteIntLiteral itself, rather than in the fact that we are using it to convert 0xffff to signed int.

ontes avatar Apr 10 '22 07:04 ontes