-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
Zig Version
0.11.0-dev.1913+95f6a5935 - 0.12.0-dev.2150+63de8a598
Steps to Reproduce and Observed Behavior
I discovered this while investigating a compile error when trying to include linmath.h discovered by abcode89 on the zig discord.
I could reduce the issue to the following zig code which was (with some reductions) produced by translate_c:
pub fn main() void {
var array2d: [42][4]f32 = undefined;
const cPointer: [*c][4]f32 = &array2d;
(cPointer + 5).*[0] = 0;
}Behavior:
$ zig run test.zig
test.zig:4:24: error: expected type '[4]f32', found 'comptime_int'
(cPointer + 5).*[0] = 0;
^
referenced by:
callMain: /home/mint/Downloads/zig/lib/std/start.zig:607:17
initEventLoopAndCallMain: /home/mint/Downloads/zig/lib/std/start.zig:551:34
remaining reference traces hidden; use '-freference-trace' to see all reference traces
It works when printing the value of (cPointer + 5).*[0] works correctly and has the correct type.
It also works when doing (cPointer + 5)[0][0] = 0;
Expected Behavior
There should be no compiler error.
.* and [0] should behave the same for C pointers.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior