Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does stdarg.h have a macro « __va_size »?

I was looking for some code about macros, and I found a code like this, for the macro « va_start » :

#define __va_argsiz(t)  \
    (((sizeof(t) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
#define va_start(ap, pN)    \
    ((ap) = ((va_list) (&pN) + __va_argsiz(pN)))

I would like to know what is the goal of « __va_argsiz » function exactly. Is it alignment limitations ?

Thanks !

like image 382
md5 Avatar asked Apr 27 '12 07:04

md5


2 Answers

Both alignment, and the default type promotion rules in C.

like image 100
geekosaur Avatar answered Oct 01 '22 23:10

geekosaur


It looks like it is used to compute the start of the variable argument list, based on the size of the first argument. The first argument is the required normal one, i.e. for printf() it would be the pointer to the formatting string.

like image 42
unwind Avatar answered Oct 02 '22 00:10

unwind