Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > VA_START called inside a function with fixed number of arguments

Reply
Thread Tools

VA_START called inside a function with fixed number of arguments

 
 
mahesha
Guest
Posts: n/a
 
      10-05-2006
What should be the behaviour of following program?. Is this behaviour
is undefined or compiler should report error for this case?. Can
anybody point me to pages in the standard where it is explained.

#include <stdarg.h>

void goo(int a) {
va_list args;
va_start(args, a);
}
int main() {
goo(2);
}

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-05-2006
mahesha wrote:
> What should be the behaviour of following program?. Is this behaviour
> is undefined or compiler should report error for this case?. Can
> anybody point me to pages in the standard where it is explained.
>
> #include <stdarg.h>
>
> void goo(int a) {
> va_list args;
> va_start(args, a);
> }
> int main() {
> goo(2);
> }


In the C Standard (and also reiterated in the C++ Standard), it says
that *unless* the second argument to 'va_start' is the last named
argument before the "..." (", ..." in C), the behaviour is undefined.
Essentially we can conclude that the use of that macro in a function
that does not contain the ellipsis results in undefined behaviour,
since (like the 'a' in your example above) the argument would not be
"the last *before*" the ellipsis. That's the safest assumption I can
figure out.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Larry Smith
Guest
Posts: n/a
 
      10-05-2006
mahesha wrote:
> What should be the behaviour of following program?. Is this behaviour
> is undefined or compiler should report error for this case?. Can
> anybody point me to pages in the standard where it is explained.
>
> #include <stdarg.h>
>
> void goo(int a) {
> va_list args;
> va_start(args, a);
> }
> int main() {
> goo(2);
> }
>


/* Note the '...' as the 2nd input parm to goo() */
void goo(int a, ...) {
va_list args;
va_start(args, a);
/* do stuff with args */
va_end(args);
}

 
Reply With Quote
 
Larry Smith
Guest
Posts: n/a
 
      10-05-2006
mahesha wrote:
> What should be the behaviour of following program?. Is this behaviour
> is undefined or compiler should report error for this case?. Can
> anybody point me to pages in the standard where it is explained.
>
> #include <stdarg.h>
>
> void goo(int a) {
> va_list args;
> va_start(args, a);
> }
> int main() {
> goo(2);
> }
>



http://www.penguin-soft.com/penguin/man/3/stdarg.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VA_START called inside a function with fixed number of arguments (#2) tukki C++ 0 07-30-2010 11:22 AM
Variable number of arguments for methods called with "send" Pierre Lecocq Ruby 2 04-27-2010 02:23 PM
Call again a variadic function (... variable number of arguments)with same arguments that its variadic wrapper moreau.steve@gmail.com C Programming 3 12-31-2008 07:13 AM
how to pass a function name and its arguments inside the arguments of other function? jmborr Python 1 11-03-2007 08:20 AM
Why va_start takes 2 arguments Minti C Programming 1 09-03-2004 06:39 PM



Advertisments