简体   繁体   中英

Argument list in C: increment/decrement va_arg?

I'm trying to access the next or previous element when calling va_arg in an argument list. "n" is actually the length of the argument list.

va_list pointer;

va_start(pointer, n);
int temp = va_arg(pointer, int);
...
if(temp < va_arg(pointer, int))...
...

void va_end(va_list pointer)

Is it actually possible to swap two positions of the argument list? Same thing like the swap of two integers in bubblesort.

The "list" you get from the va_* "functions" (they are most often implemented as preprocessor macros) is a part of the stack, and as a true stack you can only "pop" values of it.

So no you can't "swap" values, or go backwards. You can't even "push" values, only "pop".

If you want to swap values, you have to get both values into variables, and swap the values of those variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM