简体   繁体   English

C中的参数列表:递增/递减va_arg?

[英]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. 我在参数列表中调用va_arg时尝试访问下一个或上一个元素。 "n" is actually the length of the argument list. “ n”实际上是参数列表的长度。

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. 就像在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. va_* “函数”获得的“列表”(它们通常实现为预处理器宏)是堆栈的一部分,而作为真正的堆栈,您只能“弹出”其值。

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. 如果要交换值,则必须将两个值都放入变量中,并交换这些变量的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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