0

If I have a simple function in C

like

int print(int x)
{

  int x;
  x=getNextNum()

  return x;    
}

is it correct to say in above function there is a continuous stack frame against function print address in above code

and how the stack frame of static functions differentiated from simple functions like above function.

for example I have a sttic function

static void print(int x)
{

int x;
x=8;

}

I know that if we want to reuse the name of a function/ and like same signature in other files then we can mark it with static keyword at start of function signature. Is there any other explanation that differentiating static functions and normal functions in terms of storage. what is I use malloc inside static function then will variable still be dynamic stack allocated so how its different from normal functions. also in terms of stack frame of variables allocated without malloc like int or char on stack

1 Answer 1

0

There is no difference between static and non-static functions except the linkage. static functions do not have external linkage and are visible only in one compilation units.

what is I use malloc inside static function then will variable still be dynamic stack allocated

First of all C language does not know anything about the stack. Stack is used in most modern implementations. In those implementations dynamic allocation does not happen on the stack only in different memory area called the heap. There is no difference difference between static and non static functions.

Local automatic automatic storage duration variables are allocated the same way despite the function linkage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.