gca*_*dal 0 c c++ solaris extern sunstudio
请考虑以下代码:
extern "C" {
#include <lib.h>
}
#include <iostream>
int main() {
unsigned char a='a';
unsigned char b=some_struct_in_libh->unsignedchar;
cout << a << " " << b << endl; //Prints only a
printf("%u\n",b); //Prints b
cout << static_cast<int>(b) << endl; //Also prints b
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么它会像这样?
它根本不打印a.你所看到的是将cout字符类型数据打印为字符而不是数字.您b的某些字符是不可打印的,因此cout有助于将其打印为空白区域.
您通过将其转换为int找到了解决方案.
编辑:我很确定你的printf只是偶然工作,因为你告诉它期望一个unsigned int并给它一个字符(不同的字节数).