__BUILTIN_RETURN_ADDRESS(3)
β¨ __BUILTIN_RETURN_ADDRESS(3) β¨
okay bestie, so this one's a page from the Library Functions Manual and it's all about two little GNU compiler built-ins that let you peek at the call stack π«Ά. Buckle up, it's giving "intro to stack frames but make it cute" π
πΈ NAME πΈ
__builtin_return_address β literally just: the return address of a function π
π SYNOPSIS π
void *
__builtin_return_address(unsigned int level);
void *
__builtin_frame_address(unsigned int level);
π¦ DESCRIPTION π¦
So __builtin_return_address() is a GNU extension β aka not standard C, it's a GCC thing β and what it does is hand you the return address of the current function, or of one of the callers up the chain. Iconic, honestly π
The parameter level is the vibe check for how many frames you wanna scan up the call stack:
0β you get the address of the current function1β you get the address of the caller of the current function2β you get the address of the caller's caller- and so on, forever, until you run out of stack πΈ
If you've hit the top of the call stack, the function returns 0. Also important, bestie: on some architectures it's only possible to determine the address of the current function. In those cases it also returns 0. So like, it's usually safe to only use the value 0 for level β no cap, that's the move π
Then there's __builtin_frame_address(), which behaves similarly but returns the address of the function frame instead of the function's return address. Same energy, different address π«
β SEE ALSO β
π CAVEATS π
These are non-standard, compiler-specific extensions. Periodt. Don't expect your other compilers to know what you're talking about π
fr fr read the caveats again before you ship anything with these in it π
and that's the whole page, bestie!! written by the Debian girlies, dated December 19, 2010 β oldie but a goodie, and this manual page is forever __BUILTIN_RETURN_ADDRESS(3) coded ππβ¨
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2010 Jukka Ruohonen <jruohonen@iki.fi>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms