Arguments on the stack.

This is a discussion on Arguments on the stack. within the C Programming forums, part of the General Programming Boards category; Is there anyway to determine the number of arguments on the stack? Ie a way to find the number of ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195

    Arguments on the stack.

    Is there anyway to determine the number of arguments on the stack? Ie a way to find the number of hidden arguments passed to a function.

  2. #2
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    Hidden arguments? Are you asking about variable argument lists?

    In general, there is no single answer to your question, as different compilers/CPU architectures have different subroutine linkage conventions and mechanisms. Linkage pointers, parameter counts, and simply blind faith have all been used.

    If you're talking about printf() like functions, varargs is the standard way to deal with them.
    Insert obnoxious but pithy remark here

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    I mean something like this

    Code:
    #include <stdio.h>
    
    int prabs(int i){
      int v = i < 0 ? -i : i;
      printf("%d\n",v);
      return v;
    }
    
    int main(void){
    
      prabs(5);
      return 0;
    }
    The question arises from a comment made by one of the NetBSD engineers. He had made a comment that if there was one hidden argument, then there would be N args, but N+1 arguments on the stack for non-static functions. I just wanted to see how much truth there was to this statement.

    Or it could be I just missed the larger context in which he was speaking of at the time.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Probably talking about the 'this' pointer which is usually passed as a hidden parameter when using member functions of a C++ class.

    As for C, that's highly implementation specific.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-12-2006, 12:41 AM
  2. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 02:56 AM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 06:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21