0

Is this possible to write a variable argument macro like this:

#include <stdio.h>
#include <stdarg.h>

#define func(x, ...)\
{\
         va_list ap;\
         va_start(ap, x);\
         int y = va_arg(ap, int);\
         printf("y is %d\n",y);\
}\

int main()
{
        int x;
        func(5, 4);
        return 0;
}

I found an interview question which asked how to write a variable argument macro so I gave it a try. I am getting compile error though.

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by johndoe444
1

Don't do that even if you would. The macro is too large and will greatly increase the size of the final program. Just write a normal function that takes variable arguments.

0

But anyway what would be the question to the interview question? I found in some forum posting real interview questions (I guess it is asked by bloomberg which asks all sorts of peculiar c questions)

0

But anyway what would be the question to the interview question? I found in some forum posting real interview questions (I guess it is asked by bloomberg which asks all sorts of peculiar c questions)

Oh I see -- its one of those questions someone asks to see if you really know your stuff.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.