> But what it this space of 50K contain? Is it only the instructions of the program, or together with the space allocated for the variables?
It probably means everything (except dynamic memory allocation), if you're just loading this onto a bare board.
Example.
Code:
$ cat foo.c
#include <stdio.h>
int global = 0;
char msg[] = "hello world";
int main ( ) {
int local = 1;
printf("%d %d %s\n", local, global, msg );
}
$ gcc -c foo.c
$ size foo.o
text data bss dec hex filename
115 12 4 131 83 foo.o
So in this example, the generated assembler of main() occupies 115 bytes (the text section), the global array msg is 12 bytes(data) and the global variable(
bss) is 4 bytes.
Finding out how much
stack space (at compile time) is trickier.
For simple code with a straightforward call relationship, it's pretty easy to work out.
It gets harder if you have like many 20+ nested function paths, as you need to sum each call path in turn to work out what the maximum depth is.
a() -> b() -> c() -> d() -> e() might be less than x() -> y(), if say y has lots of local variables.
Things get messy though if you have recursive calls, or variable length arrays on the stack.
Your default stack size might be quite large, but you should be able to configure it down to a really small size if your code is simple enough.