Skip to content

Instantly share code, notes, and snippets.

@emekoi
Created February 23, 2019 22:22
Show Gist options
  • Save emekoi/110d2f7e410e094e988a5aa0925e948d to your computer and use it in GitHub Desktop.
Save emekoi/110d2f7e410e094e988a5aa0925e948d to your computer and use it in GitHub Desktop.
const std = @import("std");
const Foo = struct {
bar: usize,
bytes: []u8
};
pub fn foo(bytes: []u8) void {
var boo = @fieldParentPtr(Foo, "bytes", &bytes);
std.debug.warn("{}\n", @ptrToInt(boo));
}
pub fn main() !void {
var bax = try std.debug.global_allocator.create(Foo);
bax.bytes = try std.debug.global_allocator.alloc(u8, 10);
std.debug.warn("{}\n", @ptrToInt(bax));
foo(bax.bytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment