473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

VA_START called inside a function with fixed number of arguments

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);
}

Oct 5 '06 #1
3 3528
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
Oct 5 '06 #2
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);
}

Oct 5 '06 #3
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

Oct 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: frankg | last post by:
When I compile this file ------------------------------------------------------ #include <stdarg.h> template <class Any> void var_arg_func(int dimension_count, ...) { int dimensions;...
3
by: Douwe | last post by:
I try to build my own version of printf which just passes all arguments to the original printf. As long as I keep it with the single argument version everything is fine. But their is also a version...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
17
by: gyan | last post by:
Why it is that following program behaving like this: 1 #include <stdlib.h> 2 #include <stdarg.h> 3 #include <stdio.h> 4 5 void comd(char *p,int a, ...); 6 void f(void); 7 8 main(){
4
by: Sekhar | last post by:
While using variable arguments we have to initialize variable argument like va_start( arg_ptr, prevParam ); Can any body explain what is the significance of second parameter(prevParam) while...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
11
by: Felix Kater | last post by:
Hi, I can compile and run this code (see below) which twice calls the function f, first with too less, second with too much arguments. But is it legal and free of memory leaks and other...
4
by: mainargv | last post by:
hi How do you rewrite codes with " ... va_list va_start va_etc", so that simple c compiler don't have to deal with them. I have written a simple c->verilog compiler but it can't deal with...
34
by: Srinu | last post by:
Hi all, Can we assign return value of a function to a global variable? As we know, main() will be the first function to be executed. but if the above is true, then we have a function call before...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.