你好,我有一个关于va_start的问题 [英] hello i have a question about va_start
本文介绍了你好,我有一个关于va_start的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我了解va_start,但无法理解此代码:
Hello,
I''m understanding the va_start, but I can''t understand this code:
typedef int s32;
typedef s32 acpi_native_int;
#define _AUPBND (sizeof (acpi_native_int) - 1)
#define _ADNBND (sizeof (acpi_native_int) - 1)
// Variable argument list macro definitions
#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
#define va_arg(ap, T) (*(T *)(((ap) += (_bnd (T, _AUPBND))) - (_bnd (T,_ADNBND))))
#define va_end(ap) (void) 0
#define va_start(ap, A) (void) ((ap) = (((char *) &(A)) + (_bnd (A,_AUPBND))))
请告诉我_bnd的功能,
谢谢您.
Please tell me the feature of the _bnd,
thank you
推荐答案
我认为_bnd(X,bnd)的功能是将X(缓冲区的长度)设置为int
<的倍数. br/>
举个例子
1
I think the feature of _bnd(X, bnd) is set length of X(buffer or you could it array) to multiple ofint
take a exmple
1
struct
{
char c1 ;
char c2 ;
char c3 ;
} A ; //length of A is 3 Bytes = 24 bit
(_bnd (A,_AUPBND)
2
2
typedef int s32; //assume int is 2 Bytes
typedef s32 acpi_native_int;
//value of _AUPBND should be 1. it is "0000 0001" in memory
#define _AUPBND (sizeof (acpi_native_int) - 1)
3(_bnd(A,_AUPBND)应该是(_bnd(A,1))
3 (_bnd (A,_AUPBND) should be (_bnd (A,1))
#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) &(~(bnd)))
//_bnd (A,1)
//sizeof(A) = 3 "0000 0011" in memory
//3 + 1 = 4 "0000 0100" in memory
//(~(1)) = "1111 1110" in memory
//final step
//4 & (~(1)) = 4 "0000 0100" in memory
//and you will found the lowest-1bits always has been clean to zero.
//because this will insure result of _bnd is multiple of int
//first time A is 3 Bytes , now _bnd return 4 (Bytes) is multiple of int
我希望我说对了
I hope I said right
据我所见,这是一个宏,用于确定arg数组中参数的大小,以便计算从va_start
到下一个的偏移量争论.请记住,有些参数可能是指针(32或64位),而有些则可能是值(8、16、32、64 ...).
As far as I can see this is a macro to determine the size of the parameters in the arg array in order to calculate the offset from va_start
to the next argument. Remember that some arguments may be pointers (32 or 64 bits) while some may be values (8, 16, 32, 64 ...).
这篇关于你好,我有一个关于va_start的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文