将类型转换为 va_arg return
Cast type to va_arg return
我可以将类型转换为 va_arg return 吗?
据我所知,va_arg 无法读取-return char/short int 类型
if (flags->size == 0)
u->s = (char)va_arg(pt, int);
if (flags->size == 1)
u->s = (short int)va_arg(pt, int);
标准规定
The va_arg
macro expands to an expression that has the specified type and the value of the next argument in the call.
这样的表达式是由宏扩展产生的,这一事实与它的使用方式无关。特别是,当指定给 va_arg
的类型是 int
时,得到的 int
类型的表达式当然可以转换为其他整数类型,前提是 va_arg()
的行为是已定义(大致意思是 int
与实际参数的提升类型兼容)。
所以是的,您可以转换 va_arg()
的结果。
来自文档:
va_arg
returns the current argument
因此,在您的情况下,returns pt
指向的值是 int
。所以是的,您可以转换该值。
我可以将类型转换为 va_arg return 吗? 据我所知,va_arg 无法读取-return char/short int 类型
if (flags->size == 0)
u->s = (char)va_arg(pt, int);
if (flags->size == 1)
u->s = (short int)va_arg(pt, int);
标准规定
The
va_arg
macro expands to an expression that has the specified type and the value of the next argument in the call.
这样的表达式是由宏扩展产生的,这一事实与它的使用方式无关。特别是,当指定给 va_arg
的类型是 int
时,得到的 int
类型的表达式当然可以转换为其他整数类型,前提是 va_arg()
的行为是已定义(大致意思是 int
与实际参数的提升类型兼容)。
所以是的,您可以转换 va_arg()
的结果。
来自文档:
va_arg
returns the current argument
因此,在您的情况下,returns pt
指向的值是 int
。所以是的,您可以转换该值。