Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:31:12+00:00 2026-06-11T02:31:12+00:00

int max(int n, …) I am using cdecl calling convention where the caller cleans

  • 0
int max(int n, ...)

I am using cdecl calling convention where the caller cleans up the variable after the callee returns.

I am interested in knowing how do the macros va_end, va_start and va_arg work?

Does the caller pass in the address of the array of arguments as the second argument to max?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:31:13+00:00Added an answer on June 11, 2026 at 2:31 am

    If you look at the way the C language stores the parameters on the stack, the way the macros work should become clear:-

    Higher memory address    Last parameter
                             Penultimate parameter
                             ....
                             Second parameter
    Lower memory address     First parameter
           StackPointer  ->  Return address
    

    (note, depending on the hardware the stack pointer maybe one line down and the higher and lower may be swapped)

    The arguments are always stored like this1, even without the ... parameter type.

    The va_start macro just sets up a pointer to the first function parameter, e.g.:-

     void func (int a, ...)
     { 
       // va_start
       char *p = (char *) &a + sizeof a;
     }
    

    which makes p point to the second parameter. The va_arg macro does this:-

     void func (int a, ...)
     { 
       // va_start
       char *p = (char *) &a + sizeof a;
    
       // va_arg
       int i1 = *((int *)p);
       p += sizeof (int);
    
       // va_arg
       int i2 = *((int *)p);
       p += sizeof (int);
    
       // va_arg
       long i2 = *((long *)p);
       p += sizeof (long);
     }
    

    The va_end macro just sets the p value to NULL.

    NOTES:

    1. Optimising compilers and some RISC CPUs store parameters in registers rather than use the stack. The presence of the ... parameter would switch off this ability and for the compiler to use the stack.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this code using Google. private int RandomNumber(int min, int max) { Random
What method returns a random int between a min and max? Or does no
I tryed to get MAX value for int, using tilde.But output is not what
int max(int N, ...){ int* x = &N; x = x + 1; int
params.max = Math.min(params.max ? params.int('max') : 2, 100) orders=OrderInfo.createCriteria().listDistinct() For pagination, we need to
in my database we have a field which is going beyond int max value,
This is my function: Random(int min, int max) { srand(time(NULL)); return (rand() % (max-min))
#define MAX 100 struct bs{ int ab; int ac; }be; struct s{ be b;
I have this code: public static int MAX; public static int MIN; public static
I am using input filter: int max_length; max_length = 15; InputFilter[] FilterArray = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.