Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22052

Is there a way to force gcc to start a new stack frame for a block?

$
0
0

In embedded C++ code where RAM and hence stack space is limited, I often come across this situation:

void f(parameters) {  if (condition) g(...);   // g uses lots of stack space  else {    int table[1000];    // do something involving table  }}

Gcc allocates space for 'table' on the stack at the start of the function, which means that the stack must be large enough to accommodate both 'table' and the stack needed by g() even though these are not used at the same time.

I want to tell gcc to allocate a new stack frame for the { } block that comprises the else-part. That way the stack would only needs to be large enough to accommodate the larger of 'table' (plus other stack needed in the else part) and stack needed by the call to g(). Is there a way to do this?

My usual workaround is to turn the else-block into another function call and mark that function not to be inlined; but in some cases such a solution is ugly because the function needs a large number of parameters to pass values computed earlier in f().


Viewing all articles
Browse latest Browse all 22052

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>