Zig struggles with linking or translating arrays of c-string #22315
Labels
bug
Observed behavior contradicts documented or intended behavior
translate-c
C to Zig source translation feature (@cImport)
Milestone
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
Consider the following C file
This code is valid C and will produce all the strings listed without issue. The simple case is well supported and is not an issue. It however becomes an issue with both case2 and case3.
Consider the translated code
Case1 is again handled correctly with appropriate casts. Case2 and case3 have issues however.
Expected Behavior
Both with linking and translating I would expect case2 and case3 to work as they are valid(perhaps a tad unconventional) c.
I would guess that a number of additional casts is required to make the code work as if it were c.
These added constCasts seem to work.
Case3 was the original case I encountered, where is the error
expected type '[4]u8', found '*const [3:0]u8'
pops up. This is harder to solve as it might have arbitrary data after the null-sentinel in the string. I do not know if there are appropriate casts possible here.When linking the code as c code case 2 gives
error: expected type '[[*c]u8', found '*const [3:0]u8](cimport.zig:1151:9: error: expected type '[*c]u8', found '*const [3:0]u8')
and case 3 givescimport.zig:1151:9: error: expected type '[4]u8', found '*const [3:0]u8'
which indicate the same problem. As the code is valid c, it should also be accepted and used as is.The text was updated successfully, but these errors were encountered: