# How to retrieve function names via \`@typeInfo\` in zig 0.17.0?

**URL:** <https://ziggit.dev/t/how-to-retrieve-function-names-via-typeinfo-in-zig-0-17-0/16750>\
**Category:** Help\
**Tags:** language, standard-library\
**Created:** [July 17, 2026, 8:22am UTC](https://ziggit.dev/t/how-to-retrieve-function-names-via-typeinfo-in-zig-0-17-0/16750 "2026-07-17T08:22:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashley.h](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/bcef8e/32.png) [@ashley.h](https://ziggit.dev/u/ashley.h)\
**Post date:** [July 17, 2026, 8:22am UTC](https://ziggit.dev/t/how-to-retrieve-function-names-via-typeinfo-in-zig-0-17-0/16750/1 "2026-07-17T08:22:54Z")

</div>

I see some posts here [example](https://ziggit.dev/t/discovering-public-functions-via-reflection/3703) that older versions of zig allowed to retrieve function names via `@typeInfo` but I try to do it and there are only field names…

```zig
const anon = struct {
    tte: u32,
    pub fn ttr() void {}
};

const stripped = stripNamespace(anon);
pub fn main() !void {
    stripped.r(); // just to force evaluation of sstripped var
}

// needs to strip the `tt` prefix
fn stripNamespace(comptime space: type) type {
    const info = @typeInfo(space).@"struct";

    // @as(usize, 1)
    @compileLog(info.decl_names.len);

    // There are no entries for functions
    // @as([:0]const u8, "ttr"[0..3])
    for (info.decl_names) |name| {
        @compileLog(name);
    }

    return @TypeOf(info); // stub
}

```

Note the result is the same with `field_names` and `decl_names`. As far as I understand (from reading old posts and docs) `field_names` must really contain only field names while `decl_names` should be a superset of `field_names` and contain also functions and other stuff? (I am not sure what other stuff it could be except functions). And if this understanding is correct (unlikely) it means a compiler bug?

---

<div class="post-metadata">

**Author:** ![rpkak](https://ziggit.dev/letter_avatar_proxy/v4/letter/r/a4c791/32.png) [@rpkak](https://ziggit.dev/u/rpkak)\
**Post date:** [July 17, 2026, 8:29am UTC](https://ziggit.dev/t/how-to-retrieve-function-names-via-typeinfo-in-zig-0-17-0/16750/3 "2026-07-17T08:29:01Z")

</div>

When you do

```zig
    for (info.decl_names) |name| {
        @compileLog(name);
    }

```

you get `@as([:0]const u8, "ttr"[0..3])`, which is the function name.

When you do

```zig
    for (info.field_names) |name| {
        @compileLog(name);
    }

```

you get `@as([:0]const u8, "tte"[0..3])`, which is the field name.

---

<div class="post-metadata">

**Author:** ![ashley.h](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/bcef8e/32.png) [@ashley.h](https://ziggit.dev/u/ashley.h)\
**Post date:** [July 17, 2026, 8:30am UTC](https://ziggit.dev/t/how-to-retrieve-function-names-via-typeinfo-in-zig-0-17-0/16750/4 "2026-07-17T08:30:47Z")

</div>

I am definetely stupid sorry

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [July 17, 2026, 3:18pm UTC](https://ziggit.dev/t/how-to-retrieve-function-names-via-typeinfo-in-zig-0-17-0/16750/5 "2026-07-17T15:18:00Z")

</div>

I think this old hack that is not using `@typeInfo`, but `@typeName` with a generic, probably still works:

> [@Is there a way to get the function name from pointer](https://ziggit.dev/t/is-there-a-way-to-get-the-function-name-from-pointer/3951/3):
>
> You can in a roundabout way. When you use a comptime function to define a struct type, the arguments given will end up in the type name: const std = @import("std"); fn Useless(comptime arg: anytype) type { return struct { const stuff = arg; }; } pub fn main() void { std.debug.print("{s}\n", .{@typeName(Useless(1234))}); std.debug.print("{s}\n", .{@typeName(Useless(.{ .pierogi = 12 }))}); } fname.Useless(1234) fname.Useless(.{ .pierogi = 12 }) If you pass a function a…

But it is still questionable whether you should rely upon it, I guess it would be good to at least add a unity test that makes sure that it still works, so you get notified if it eventually breaks (If it wouldn’t be immediately obvious to how your code uses it).

```zig
fn functionName(comptime func: anytype) []const u8 {
    const T = @TypeOf(func);
    std.debug.assert(@typeInfo(T) == .@"fn");
    const wrapper_name = @typeName(Wrapper(func));

    var it = std.mem.splitSequence(u8, wrapper_name, ".Wrapper((function '");
    _ = it.first();
    const rest = it.next().?;
    return rest[0 .. rest.len - 3];
}

test functionName {
    try std.testing.expectEqualStrings("Wrapper", functionName(Wrapper));
    try std.testing.expectEqualStrings("add", functionName(add));
    try std.testing.expectEqualStrings("splitSequence", functionName(std.mem.splitSequence));
}

fn Wrapper(comptime arg: anytype) type {
    return struct {
        const stuff = arg;
    };
}

fn add(a: i32, b: i32) i32 {
    return a + b;
}

const std = @import("std");

```

related: [Getting function name at comptime and stringify](https://ziggit.dev/t/getting-function-name-at-comptime-and-stringify/4459)
