Idea: __thread __attribute__((recurse_depth)) unsigned depth;
Example usage
unsigned foo_limit = FOO_LIMIT;
unsigned
int
When GCC compiles foo() it would insert an increment of depth at the top of foo() and a decrement before every return. Makes it easier to write code that protects against stack overflows caused by recursion.
Edit: GCC should also throw an error when the developer tries to directly modify it or grab it's address
Edit 2: GCC should also throw an error when the developer tries to initialise it to anything other than 0 or give it a signed type
1
Upvotes