Created
July 30, 2024 08:05
-
-
Save 50n1cd347h9/bf9348665d721fb429926ead08f27b3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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