If you are ready to accept a run-time error and penetrate deeply into the implementation water, and if your DSP has a suitable address layout, you can simply insert this location check into the default constructor of Vector64.
If you know the address space in advance, the safest (in terms of language) is simply to compare the absolute position of the stack.
struct Vector64 { Vector64() { assert( reinterpret_cast<uintptr_t>(this) < STACK_START ); } };
A riskier but more flexible definition might look like this:
__attribute__((noinline)) Vector64() { int test; assert( less<void*>()(this, &test) ); }
Where __attribute__((noinline)) necessary to prevent clang from ordering the selection of test before the Vector64 object (or just defining it elsewhere). On the bright side, reordering optimization cannot make it claim to throw a false positive, only fail silently. std::less also important here, because unlike < it explicitly allows comparisons between the addresses of different objects.
This approach is rather unpleasant, but by interfering with construction, you have a better chance of preventing stack overflows at runtime, ensuring that they will no longer be built.
source share