(part 16) Han from China answers your C questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nomen Nescio

    (part 16) Han from China answers your C questions

    memory used while declaring function

    c.lang.myself@g mail.com said:
    Is there any memory allocated in stack when declaring a function
    e.g void fun(int a,int b,int c);
    Is it true that compiler reserves 3 stack spaces for parameters a ,b
    and c....
    Pushing the three arguments on a stack is one way of implementing
    a function CALL (but not the only way).

    As for function DECLARATIONS, I would say no. However, I can't
    think of any reasons why a compiler COULDN'T pre-allocate some space
    SOMEWHERE for AT LEAST ONE invocation of the function. Think about
    why I said "AT LEAST ONE". What happens to the arguments in the
    following cases?

    fun() ---fun()
    fun() ---scrotum() ---fun()


    Yours,
    Han from China

  • Richard Tobin

    #2
    Re: (part 16) Han from China answers your C questions

    In article <cece8a611fe5c7 ac493346237941c 6e7@dizum.com>,
    Nomen Nescio <nobody@dizum.c omwrote:
    >As for function DECLARATIONS, I would say no. However, I can't
    >think of any reasons why a compiler COULDN'T pre-allocate some space
    >SOMEWHERE for AT LEAST ONE invocation of the function.
    In languages that didn't allow recursion (e.g. old Fortran), it was
    common to allocate fixed locations for the arguments and local
    variables of functions. In effect, you could make all variables
    static by renaming.

    -- Richard
    --
    Please remember to mention me / in tapes you leave behind.

    Comment

    Working...