# String handling in comptime functions

**URL:** <https://ziggit.dev/t/string-handling-in-comptime-functions/6703>\
**Category:** Help\
**Tags:** language\
**Created:** [November 5, 2024, 4:51pm UTC](https://ziggit.dev/t/string-handling-in-comptime-functions/6703 "2024-11-05T16:51:40Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![castholm](https://ziggit.dev/user_avatar/ziggit.dev/castholm/32/1330_2.png) [@castholm](https://ziggit.dev/u/castholm)\
**Post date:** [November 5, 2024, 5:48pm UTC](https://ziggit.dev/t/string-handling-in-comptime-functions/6703/2 "2024-11-05T17:48:50Z")

</div>

[Comptime-Mutable Memory Changes](https://ziggit.dev/t/comptime-mutable-memory-changes/3702) is a very good and thorough summary of what is and isn’t allowed to become runtime-known, but the relevant part is this:

> [@Comptime-Mutable Memory Changes](https://ziggit.dev/t/comptime-mutable-memory-changes/3702/1):
>
> The most likely way for this to manifest is in a function computing a slice at comptime by filling an array. To fix the error, copy your finalized array to a `const` before taking a pointer.

So the easiest fix is probably something like this:

```diff
 pub fn getMetaname(comptime T: type) [:0]const u8 {
     const fullTypeName = @typeName(T);
     var it = std.mem.splitBackwardsAny(u8, fullTypeName, ".");
     const last = it.first();
     var buffer: [128]u8 = undefined;
     @memcpy(buffer[0..last.len], last);
     buffer[last.len] = 0;
- return buffer[0..last.len :0];
+ const copy = buffer[0..last.len :0].*;
+ return &copy;
 }

 pub const metaname = getMetaname(LdtkScene);

```

---

_[View the full topic](https://ziggit.dev/t/string-handling-in-comptime-functions/6703)._
