void func(void){char array[24];}
all 25 bytes are put in to stack.
24 bytes, not 25.
Is there a rule what is the longest array that I can put in to stack or when I have a local array it should be always declared as static?
There is no such rule, you just have to be reasonable, where "reasonable" depends on your platform (eg. it would be less in the kernel with 4k stacks than in userspace application with typically ~1MB stacks).
However, I would advise against changing local arrays to static arrays for speed reasons. Function static variables still have the vices of global variables, that they make the function not reentrant. This might or might not be an issue, but the first choice solution when dealing with excessive stack usage should be moving the variable to the free store:
void func(void){
char* array=malloc(24);
/* do something */
free(array);
}
mallocet al.? They are the usual methods of moving data off the stack, sincestatichas other implications.staticthen it is shared between all concurrently-executing calls to your function. If the array is automatic, each call to the function has its own instance of the variable. That's why you can't say, "it should always be declared as static", because in many situations that sharing is not acceptable.