#[solved] Which []u8 type is the most compatible with C?

1 messages · Page 1 of 1 (latest)

golden creek
#

☝️ basically

round summit
#

[*c]u8

golden creek
#

right, but that IS the C type

#

I mean native/normal zig slice that can be sent to C

round summit
#

Other than that, it depends on the context. For a C string ?[*:0]u8

idle spear
# golden creek ☝️ basically

there is no one answer to this question, since the semantics of []u8 dont directly exist in C, can you provide a code sample of what the C side looks like?

golden creek
idle spear
golden creek
#

but I need to pass the string around my zig code

idle spear
#

then [:0]u8

round summit
#

[:0]u8 should be fine. Then pass the .ptr property to C

empty hinge
golden creek
#

the .ptr idea might be the way to go, yeah

idle spear
#

[]u8 has no set memory layout, the compiler is free to lay it out in any way

idle spear
golden creek
#

✍️

hard notch
golden creek
#
pub const A = [:0]const u8;
pub const B = [*:0]const u8;

btw, what is the difference from Zig's code from using these two?

#

is it reasonable to use B in general, or is there any reason to avoid it and prefer A?

hoary zenith
#

Top has length information

#

Bottom have to iterate through the values it points to to find lenght

golden creek
#

ah, i see. definitely A for the zig code then, tyty