0

I'm trying to understand static keyword by having a deeper look at the memory layout, but i'm quite confused with the static method/function.

#include <iostream> 

void staticFunction () {
    int a = 10; //this variable would be in the stack
}

static void staticFunction1 () { 
    int a = 20; //if this static function is called, what part of the memory does content variables is it stored? is it in still in the stack?
}

int main () {
    staticFunction(); //this function is created in the stack which then creates a stack frame 
    staticFunction1();
return 0;
}

This is how i visualize what the memory layout for int main would look like, which one is correct? enter image description here

Renz Carillo
  • 349
  • 2
  • 11
  • 1
    Unfortunately, the `static` keyword [means several different things](https://stackoverflow.com/q/572547/10871073) in C and C++. On a function definition, it really just says that the function isn't visible outside the file where it lives. – Adrian Mole Apr 28 '21 at 09:07
  • specifially this answer: https://stackoverflow.com/a/23032972/4117728 – 463035818_is_not_an_ai Apr 28 '21 at 09:12
  • static is both a linkage specifier and a storage duration specifier. The storage duration part is not applicable to static free functions – PeterT Apr 28 '21 at 09:35

1 Answers1

0

This memory will be allocated on the stack. Some word about static functions : "static functions are functions that are only visible to other functions in the same file (more precisely the same translation unit)." Some response on stack-overflow. Post that describes it: https://www.tutorialspoint.com/static-functions-in-c

LaVuna47
  • 29
  • 6