admin管理员组

文章数量:1389779

When I have finished a software, I carry out a stack overflow test at the end. Why don't I have to do this with a compiled stack?
Are overflows really completely impossible here or only very rare?

When I have finished a software, I carry out a stack overflow test at the end. Why don't I have to do this with a compiled stack?
Are overflows really completely impossible here or only very rare?

Share Improve this question edited Mar 14 at 6:16 Mike asked Mar 13 at 15:02 MikeMike 4,3807 gold badges24 silver badges45 bronze badges 1
  • 2 Note well that the ability to use a compiled stack is an xc8-specific feature, motivated by the characteristics of some of the devices that this compiler targets. Note also that C itself does not require that there be a stack in the conventional sense at all, though there are practical considerations that make a stack a very appealing implementation choice. – John Bollinger Commented Mar 13 at 16:02
Add a comment  | 

1 Answer 1

Reset to default 7

The XC8 "compiled stack" isn't really a stack at all, in the sense of pushing and popping. It holds the kind of data that would traditionally be allocated "on the stack" - local variables - but it doesn't grow. There's no stack pointer. Everything is just allocated at a fixed address. The "stack" can't grow past its limits if it doesn't grow in the first place.

This of course runs into other limitations not found with traditional stack allocation. For example, functions that use the compiled stack can't be called recursively. All calls to such functions have their local variables allocated at the same addresses, so if you tried to make a recursive call, it'd be stomping over the original call's local variables.

You can read more in the XC8 C Compiler User's Guide, particularly section 5.5.2.2.1, "Compiled Stack Operation".

本文标签: cIs a stack overflow on a compiled stack really impossibleStack Overflow