#Function expected type [*c]const [*c]const

1 messages · Page 1 of 1 (latest)

somber narwhal
#

Hi I've run into a compile error which I'm not sure how I'm supposed to cast to the type it expects . Any help?

src/main.zig:51:40: error: expected type '[*c]const [*c]const u8', found '*const *const [100:0]u8'
    c.glShaderSource(vertex_shader, 1, &vertex_source, &vertex_source.len);
                                       ^~~~~~~~~~~~~~
src/main.zig:51:40: note: pointer type child '*const [100:0]u8' cannot cast into pointer type child '[*c]const u8'
src/main.zig:51:40: note: pointer type child '[100:0]u8' cannot cast into pointer type child 'u8'
somber narwhal
#

Not sure if this is the best way to do it but: const vert_coerce: [*]const u8 = vertex_source seemed to fix it

lyric pebble
#
pub fn compileShader(handle: u32, source: []const u8) !void {
    var length: i32 = @intCast(source.len);
    gl.shaderSource(handle, 1, @ptrCast(&source.ptr), &length);
    gl.compileShader(handle);

    var success: i32 = 0;
    gl.getShaderiv(handle, gl.COMPILE_STATUS, @ptrCast(&success));
    if (success != gl.TRUE) {
        var buffer: [1024]u8 = undefined;
        var l: i32 = 0;
        gl.getShaderInfoLog(handle, 1024, &l, (&buffer).ptr);
        std.log.err("{s}", .{buffer[0..@intCast(l)]});
        return error.FailedShaderCompilation;
    }
}
#

I do it like this

rigid urchin
#

the function expects a C pointer, so you need to coerce your zig pointers into C pointers

#

You can do that by defining a variable if you like, or by using some combination of @as and @ptrCast

#

off the top of my head it would be something like

#
@ptrCast(&@as([*c]const u8, vertex_source))
#

Something like that should work too

#

Although I may have placed the & in the wrong place