# What makes "ban returning pointer to stack memory" difficult?

**URL:** <https://ziggit.dev/t/what-makes-ban-returning-pointer-to-stack-memory-difficult/9380>\
**Category:** Explain\
**Created:** [April 1, 2025, 4:27am UTC](https://ziggit.dev/t/what-makes-ban-returning-pointer-to-stack-memory-difficult/9380 "2025-04-01T04:27:34Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![jeffective](https://ziggit.dev/user_avatar/ziggit.dev/jeffective/32/3116_2.png) [@jeffective](https://ziggit.dev/u/jeffective)\
**Post date:** [April 1, 2025, 5:09pm UTC](https://ziggit.dev/t/what-makes-ban-returning-pointer-to-stack-memory-difficult/9380/11 "2025-04-01T17:09:07Z")

</div>

It’s seems to my untrained eye that if the problems solved by [Proposal: restricted function types · Issue #23367 · ziglang/zig · GitHub](https://github.com/ziglang/zig/issues/23367) are actually solved (the compiler knowing the full function call graph), then the compiler could also know the lifetimes of all stack allocated memory, and thus detect pointers to invalid stack allocated memory.

Consider the example of an acyclic function call graph. The compiler would only need to check that a given stack variable pointer does not traverse upwards from its point of creation? I’m guessing it looks a bit like reference counting.

---

_[View the full topic](https://ziggit.dev/t/what-makes-ban-returning-pointer-to-stack-memory-difficult/9380)._
