Pelles C forum
Pelles C => Feature requests => Topic started by: CommonTater on December 19, 2012, 10:58:35 AM
-
In the current compiler setup stack optimizations are enabled whenever any other optimization is turned on, but disabled when optimizations are off.
It would be very helpful to have the stack optimizations enabled by a separate compiler switch so they can be controlled independently of other optimization strategies.
-
Tater we forget about the stack check probe:
#pragma check_stack( [ { on | off } ] )
Activable also with /Gs switch on MS compiler.
The point is that it shouldn't be available for 64bits. Maybe it could be usefull.
-
Thanks Frankie... it is at least worth experimenting with.
But from the description in the help file I don't think it does quite the same thing as what I'm asking about...
With all optimizations off, every variable in a function, regardless of scope, occupies it's own stack space for the duration of the function. This, in effect, transforms complex functions with inner scopes into standard functions, as far as the stack is concerned. (And don't forget that bracketing used with if, for, while, etc. constitutes a scope)
With any of the optimizations on (Os, Ot or Ox) the compiler switches gears and stack space for nested scopes is reused after the scope exits. The "big enough for the biggest" blob of stack memory is cleared at the end of the function.
What I'm suggesting is that these two stack strategies should be managed by a separate compiler switch so we can have more control over how the compiler manages the stack. Or, perhaps, the second strategy should be "always on".
-
Yes Tater, but at least informs you of stack problems.
-
Yes Tater, but at least informs you of stack problems.
Yes, there is that....
Below is the result of this source code...
#include <stdio.h>
typedef struct t_test
{
char str[256];
int x;
} test;
typedef struct t_test2
{
int x;
char str[256];
} test2;
int _cdecl main (void)
{
puts("Hello");
{
test t = {0};
t.x = 42;
printf("%p\n", &t);
}
{
test2 u = {0};
u.x = 13;
printf("%p\n", &u);
}
puts("bye");
return 0;
}
The left section is no optimizations, no stack check.
The center one is with no optimizations and stack check enabled.
The right one is with optimizations (any optimization) on and no stack check
As you can see the only one that reuses stack space is the +optimizations on case, which further fortifies my request for a new compiler switch... We should be able to turn on stack optimizations even if not using any other...
EDIT: Or, put another way... turning size and speed optimizations off should not cause a program to crash it's own stack.