473,401 Members | 2,127 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,401 software developers and data experts.

variable argument list

zoe
I am trying to master the variable argument list!

C99 tells me:

7.15.1.4 The va_start macro:

1 #include <stdarg.h>
void va_start(va_list ap, parmN);

4 The parameter parmN is the identifier of the rightmost parameter in
the variable parameter list in the function definition (the one just
before the , ...).
But then i see in 7.15.1.4.7:

void f3(int n_ptrs, int f4_after, ...)
{
va_list ap, ap_save;
char *array[MAXARGS];
int ptr_no = 0;
if (n_ptrs > MAXARGS)
n_ptrs = MAXARGS;
va_start(ap, n_ptrs); ??????

Should this be va_start(ap, f4_after)?

I thought that the parmN is used, by the va_start macro, to "find" the
address of the first variable argument (the one just after the one
before ,...) and let ap 'point' to that.
Am i mistaking, probably so, but where?

Zoe
Nov 13 '05 #1
3 4397
zoe wrote:

I am trying to master the variable argument list!

C99 tells me:

7.15.1.4 The va_start macro:

1 #include <stdarg.h>
void va_start(va_list ap, parmN);

4 The parameter parmN is the identifier of the rightmost parameter in
the variable parameter list in the function definition (the one just
before the , ...).

But then i see in 7.15.1.4.7:

void f3(int n_ptrs, int f4_after, ...)
{
va_list ap, ap_save;
char *array[MAXARGS];
int ptr_no = 0;
if (n_ptrs > MAXARGS)
n_ptrs = MAXARGS;
va_start(ap, n_ptrs); ??????

Should this be va_start(ap, f4_after)?

I thought that the parmN is used, by the va_start macro, to "find" the
address of the first variable argument (the one just after the one
before ,...) and let ap 'point' to that.
Am i mistaking, probably so, but where?


It looks like you've spotted a bug in the Standard;
I've cross-posted this to comp.std.c for the experts' opinion.
Fortunately (?) the error is in an example, and examples are
not normative, so we can claim that the Standard is in some
sense correct even if its "supporting documentation" is faulty.

And, yes: the va_start() should refer to `f4_after',
not to `n_ptrs'.

--
Er*********@sun.com
Nov 13 '05 #2
zoe wrote:
But then i see in 7.15.1.4.7:

void f3(int n_ptrs, int f4_after, ...)
{
va_list ap, ap_save;
char *array[MAXARGS];
int ptr_no = 0;
if (n_ptrs > MAXARGS)
n_ptrs = MAXARGS;
va_start(ap, n_ptrs); ??????

Should this be va_start(ap, f4_after)?


Yes. Looks like a copy-and-paste bug.

Jeremy.
Nov 13 '05 #3
In comp.std.c Eric Sosman <Er*********@sun.com> wrote:


It looks like you've spotted a bug in the Standard;


Noted.

-Larry Jones

Why is it you always rip your pants on the day everyone has to
demonstrate a math problem at the chalkboard? -- Calvin
Nov 13 '05 #4

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

Similar topics

0
by: Philip Rittenhouse | last post by:
I have discovered a couple of problems with the way the universal gateway code handles optional parameters and variable argument lists in COM servers. It appears to only be a problem when you...
2
by: Suzanne Vogel | last post by:
'stdarg.h' defines the 'va_arg' type to use in passing variable numbers of parameters to functions. The example of its use given in the Dinkumware documentation *seems* to imply that the 'va_arg'...
7
by: Kapt. Boogschutter | last post by:
I'm trying to create a function that has at least 1 Argument but can also contain any number of Arguments (except 0 because my function would have no meaning for 0 argument). The arguments...
7
by: | last post by:
How to call a function with variable argument list from another function again with variable argument list? Example : double average ( int num, ... ); double AFunct1 ( int num, ... ); double...
5
by: Jonathan Burd | last post by:
Greetings everyone, I wrote a function to learn about variable-length argument lists. I wonder if there is a better way to detect the end of the argument list than using a sentinel value like...
1
by: Nimmi Srivastav | last post by:
Consider two functions A and B, both of which accept a variable number of arguments (va_start, va-arg, va_end). Is there an easy way for arguments passed to A to be, in turn, passed to B? (For...
4
by: JH | last post by:
Fairly new to c# so please forgive any simple oversights. I'm developing a console app that loads dll assemblies at run time. The app scans a "plugin" directory for these dlls. Each dll is loaded...
19
by: Spiros Bousbouras | last post by:
Every time I've seen an example of a variable argument list function its functionality was to print formatted output. Does anyone have examples where the function is not some variation of printf ?
30
by: Adam | last post by:
Hi, I have a simple printf-like function: int print(const char *format, ...) { char buffer; va_list argptr; int i;
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.