yrHeTateJlb
yrHeTateJlb

Reputation: 486

Is it acceptable to use ellipsis without va_*?

I often see tutorials about ellipsis with examples like this:

void foo(int i, ...){
    int *p = &i;
    ++p;
    //...
}

And I'm just wondering, is this approach correct in terms of standard? Can I use variadic args without va_* macros? Maybe some implementations store args in reversed order, or something like this.

UPD: "Use" = pass args portably and reliably

Upvotes: 1

Views: 167

Answers (2)

dbush
dbush

Reputation: 224512

The mechanism for how parameters are passed to a function is very implementation specific. They could be passed on the stack, via registers, or some other method, and the method can differ based on the datatype.

The stdarg family of functions / macros (va_start, va_arg, va_end, etc.) specified in section 7.16 of the C standard abstracts away all this and is the only standard compliant way of handling variable arguments lists.

Upvotes: 7

Useless
Useless

Reputation: 67802

I often see tutorials about ellipsis with examples like this:

Just for absolute clarity - that example is atrocious and the tutorial best avoided.

There are valid uses (variadic templates and macros) of the ... syntax which don't require using the va_* facilities, but none of them look like the example code you posted.

Upvotes: 3

Related Questions