mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-07 14:24:43 +00:00
17 lines
421 B
Zig
17 lines
421 B
Zig
const builtin = @import("builtin");
|
|
const expect = @import("std").testing.expect;
|
|
|
|
fn get_foo() fn (*u8) usize {
|
|
comptime {
|
|
return struct {
|
|
fn func(ptr: *u8) usize {
|
|
return @intFromPtr(ptr);
|
|
}
|
|
}.func;
|
|
}
|
|
}
|
|
|
|
test "define a function in an anonymous struct in comptime" {
|
|
const foo = get_foo();
|
|
try expect(foo(@as(*u8, @ptrFromInt(12345))) == 12345);
|
|
}
|