在stdarg.h里找实现,发现有很多版本,估计是用在不同的平台上的。其中有这么一段注释:
引用:
Because of parameter passing conventions in C:
use mode=int for char, and short types
use mode=double for float types
use a pointer for array types
|
于是做了一下测试,发现对于不定参数来说确实如此,但是对于确定参数却有些许不同:
代码:
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
void pag(char a, ...) //这里符合上面的注释
{
printf("arg2 is %f, arg3 is %f",
*( (double*)((int*)(&a) + 1) ),
*( (double*)((int*)(&a) + 1) + 1 )
);
}
void pag1(char a, float b, double c)//这里char要扩充,但float还是float
{
printf("arg2 is %f, arg3 is %f",
*( (float*)((int*)(&a) + 1) ),
*( (double*)( (float*)((int*)(&a) + 1) + 1 ) )
);
}
void main(void)
{
float a = 2.47f;
double b = 10.2313;
pag(3, a, b);
pag1(3, a, b);
system("pause");
}
可能是VC6自己的名堂,反正知道了不定参数如此就可以了,嘿嘿