variable argument list

Z

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
 
E

Eric Sosman

zoe said:
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'.
 
J

Jeremy Yallop

zoe said:
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.
 
L

lawrence.jones

In comp.std.c Eric Sosman said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,812
Messages
2,569,694
Members
45,478
Latest member
dontilydondon

Latest Threads

Top