#expected type '[*c]u8', found '?*anyopaque'

1 messages · Page 1 of 1 (latest)

long knoll
#

Compiler doesn't let me access properties of a c struct referenced by c pointer, but I can't figure out how to convert it to Zig?

const sdlSurface: ?*sdl.SDL_Surface = sdl.SDL_CreateRGBSurface(
    0, // flags (empty)
    rendererWidth, rendererHeight, // surface dimensions
    32, // bit depth
    0x00ff0000, 0x0000ff00, 0x000000ff, 0 // rgba masks
);
const cr_surface = cairo.cairo_image_surface_create_for_data(
    sdlSurface.pixels,
    cairo.CAIRO_FORMAT_RGB24,
    sdlSurface.w,
    sdlSurface.h,
    sdlSurface.pitch
);
vexcess@vexcess-IdeaPad-5-Pro-16ACH6:~/Desktop/zwebsuite/zcanvas$ jvbuild build
src/window.zig:116:23: error: expected type '[*c]u8', found '?*anyopaque'
            sdlSurface.pixels,
            ~~~~~~~~~~^~~~~~~
src/window.zig:116:23: note: pointer type child 'anyopaque' cannot cast into pointer type child 'u8'
./.zig-cache/o/c6470dab6f506b21072d69b3ccc20839/cimport.zig:589:57: note: parameter type declared here
pub extern fn cairo_image_surface_create_for_data(data: [*c]u8, format: cairo_format_t, width: c_int, height: c_int, stride: c_int) ?*cairo_surface_t;
                                                        ^~~~~~
referenced by:
    main: demo/demo.zig:38:43
    main: /home/vexcess/zig-linux-x86_64/lib/std/start.zig:619:37
    3 reference(s) hidden; use '-freference-trace=5' to see all references
ebon kite
#

@ptrCast(sdlSurface.pixels) should do it. it should implicitly cast though I thought.

long knoll
#

yeah @ptrCast worked 👍

mild pollen