【发布时间】:2020-08-17 15:30:19
【问题描述】:
我在Win32 docs 上找到了这个:
// Check the smart card context handle. // hContext was set previously by SCardEstablishContext. LONG lReturn; lReturn = SCardIsValidContext(hContext); if ( SCARD_S_SUCCESS != lReturn ) { // Function failed; check return value. if ( ERROR_INVALID_HANDLE == lReturn ) printf("Handle is invalid\n"); else { // Some unexpected error occurred; report and bail out. printf("Failed SCardIsValidContext - %x\n", lReturn); exit(1); // Or other appropriate error action. } } else { // Handle is valid; proceed as needed. // ... }
printf("Failed SCardIsValidContext - %x\n", lReturn); 行将LONG 类型的参数(long 的类型定义)传递给printf,其中printf 期望unsigned int 根据cppreference.com。这是明确定义的行为吗?如果是这样,它是否与显式 static_cast 到 unsigned int 相同?
【问题讨论】:
标签: c++ printf variadic-functions