I am doing embedded programming where saving memory is important.
How much stack space would the following C code occupy at run-time?
if (send_small_message) {
uint8_t buffer[16000];
// do something with the buffer
} else {
uint8_t buffer[32000];
// do something the with buffer
}
Could some compiler decide to allocate 16000 + 32000 = 48kB stack space for both buffers? Or is it guaranteed that since both buffers will never be used at the same time, the compiler will allocate only 32kB - the size of the larger buffer?
FOLLOW UP QUESTION:
void SendSmallMessage() {
uint8_t buffer[16000];
// do something with the buffer
}
void SendLargeMessage() {
uint8_t buffer[32000];
// do something with the buffer
}
Can a code compiled by some compiler use 16000 + 32000 bytes at run-time to execute the snippet below:
if (send_small_message) {
SendSmallMessage();
} else {
SendLargeMessage();
}