linux-sysprog · beginner · ~15 min

Why not return a stack address?

Avoid returning a pointer to the thread's dead stack.

Challenge

Implement int return_method_safe(const char *how) returning 1 for "heap-pointer" or "value-via-intptr" and 0 for "address-of-local" (which dangles after the thread exits).

Starter code

#include <string.h>

int return_method_safe(const char *how) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.