Skip to content

Instantly share code, notes, and snippets.

@50n1cd347h9
Created July 30, 2024 08:05
Show Gist options
  • Save 50n1cd347h9/bf9348665d721fb429926ead08f27b3d to your computer and use it in GitHub Desktop.
Save 50n1cd347h9/bf9348665d721fb429926ead08f27b3d to your computer and use it in GitHub Desktop.
const std = @import("std");
const c = std.c;
fn ahi(val: ?*anyopaque) callconv(.C) ?*anyopaque {
const p = @as(*u32, @ptrCast(@alignCast(val)));
std.debug.print("val 0x{x}\n", .{p.*});
return p;
}
pub fn main() !void {
var tid: c.pthread_t = undefined;
var x: u32 = 0xdead;
var p: ?*anyopaque = undefined;
_ = c.pthread_create(&tid, null, ahi, &x);
_ = c.pthread_join(tid, @as(?*?*anyopaque, &p));
const xp = @as(*u32, @ptrCast(@alignCast(p)));
std.debug.print("y = 0x{x}\n", .{xp.*});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment