gpt4 book ai didi

C 格式说明符与数据类型不匹配

转载 作者:太空宇宙 更新时间:2023-11-04 05:24:01 24 4
gpt4 key购买 nike

我想知道,根据 C 规范,如果给定的数据类型与预期的格式说明符不匹配,C 中的预期行为是什么。例如:

    printf("%lu\n", 2);

最佳答案

如果可能,将根据正常升级规则(加上两个异常(exception))升级该类型。如果无法提升,则根据 7.16.1.1 在 C11 中未定义该行为(强调我的):

The va_arg macro expands to an expression that has the specified type and the value of the next argument in the call. The parameter ap shall have been initialized by the va_start or va_copy macro (without an intervening invocation of the va_end macro for the same ap). Each invocation of the va_arg macro modifies ap so that the values of successive arguments are returned in turn. The parameter type shall be a type name specified such that the type of a pointer to an object that has the specified type can be obtained simply by postfixing a * to type. If there is no actual next argument, or if type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined, except for the following cases:

  • one type is a signed integer type, the other type is the corresponding unsigned integer type, and the value is representable in both types;

  • one type is pointer to void and the other is a pointer to a character type.

关于C 格式说明符与数据类型不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41688449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com