#define BIT(n) Shift Operand (<<) that's translated from C is not working as expected #9276
Labels
bug
Observed behavior contradicts documented or intended behavior
translate-c
C to Zig source translation feature (@cImport)
Milestone
Hi,
I was working on importing a set of C libraries into zig to be used in zig. However, I found a bug either in the translate-c code or in the zig compiler. The following is the smallest example I found as I was exploring the compilation errors.
This is using Zig 0.8.0 release.
I was exporting a C preprocessor BIT(n) defined as follows:
into zig. Zig translated it into
When I tried using it through
const c = @cInclude(...)
or the translatedcimport.zig
I get an error as the following
I found out from Spex_guy#0444 that this could be a bug in the zig translate-c.
Here's the following additional info Spex_guy provided me
"Zig has extra rules about shift operands, which we are planning to change to be less restrictive. The current rule is that the rhs of a shift must be an unsigned int type with ceil(log2(number of bits in lhs type)) bits. If you don't know the lhs type statically, you can use %%std.math.Log2Int to calculate the rhs type at comptime.
translate-c should probably translate shifts to have the same semantics as C, and add an implicit cast of the rhs, I think this does count as a C translation bug."
The text was updated successfully, but these errors were encountered: