va_arg for creating a stack

This is a discussion on va_arg for creating a stack within the C Programming forums, part of the General Programming Boards category; Dear experts , i want to create a stack of arguments with va_arg, which is getting i think but when ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    99

    va_arg for creating a stack

    Dear experts ,

    i want to create a stack of arguments with va_arg, which is getting i think but when i try to read them back, means traverses the stack it gives me null please tell me proper way of cerating and traversing i am trying like this.

    Code:
    char ss[1000];
    char ........_ptr = (char *)((((int)ss)+(7)) & ~7);
    char *........_pp = (char **)((((int)ss)+(7)) & ~7);
    char *va_curptr = 0;
    int ss_cnt=0;
    
    
    
    char *sendList(int numArgs,...)
    {
    	
    	int type;
    	
    	va_list vlist;
    	
    	va_start(vlist,numArgs);
    	va_curptr = vlist;           
          /* assume
    0 -> int
    * 1 -> float
    * 2 -> string
    */
                                      switch(type)
    		{
    		case 0:	
    		         ss_ptr = (va_arg(vlist,int));
    		         ss_ptr += (vlist - va_curptr);
    		         va_curptr = vlist;
    		         ss_cnt += sizeof(int);
    			break;
    			
    		case 1:
    		          ss_fp = (double *)ss_ptr;
    		          ss_fp = ((double *)(&va_arg(vlist,double)));
    		         ss_ptr += (vlist - va_curptr);
    		         va_curptr = vlist;
    		         ss_cnt += sizeof(double);
                                               break;
                                case 2:   
    		        ss_pp = (char **)ss_ptr;
    		        ss_ptr =(char *)(&va_arg(vlist,char *));
    		        ss_ptr += (vlist - va_curptr);
    		        va_curptr = vlist;
    		        ss_cnt += sizeof(char *);
    }
    return ss;
    }
    
    
    int main()
    {
    	char * temp_ptr = sendList(6,2,"hello",1,12.25,0,34);
    
    //here i want to write a code to get the values of stack how to do.
    return 0;
    
    }
    so syntactically it is correct please tell proper way of passing any integer , float and string value inot the stack and also how to extract from stack please tell me

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    How arguments are passed to varargs functions depend on the processor type and compiler (what's often called the ABI - application binary interface).

    What are you ACTUALLY trying to achieve? Is the ultimate goal of this to send a set of data to another process or another machine?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

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