1

I'm trying to rewrite a program in Zig, but I don't know how to use pointer cast. I tried to use @as, but apparently that's wrong.

fn framebufferResizeCallback(window: ?*cInclude.GLFWwindow, _: c_int, _: c_int) callconv(.C) void {
    var app = @as(*HelloTriangleApplication, cInclude.glfwGetWindowUserPointer(window));
    app.framebufferResized = true;
}

How can I fix this?

0

1 Answer 1

3

@as is for type coercion. To do a pointer cast, you need to use @ptrCast. For example:

var app: *HelloTriangleApplication = @ptrCast(glfwGetWindowUserPointer(the_window));

or

var app = @as(*HelloTriangleApplication, @ptrCast(glfwGetWindowUserPointer(the_window)));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.