A hack for detecting stack vs heap allocated addr

Here is a simple hack that can tell whether the given address represents
a stack address or a heap address. This is not portable, but variations
of it will work on many machines.

boolean fromHeap (void* p)
{
    int i;
    return (p > &i);
}

Although not recommended for production quality code, this could be used
in assertions during development.

你可能感兴趣的:(A hack for detecting stack vs heap allocated addr)