小编Gab*_*abi的帖子

为什么这个程序的输出在C和C++之间有所不同?

可能重复:
C/C++中的字符大小('a')

以下程序

#include <stdio.h>

int main()
{
    printf("%d\n", sizeof('\0'));
    printf("%d\n", sizeof(0));
}
Run Code Online (Sandbox Code Playgroud)

用gcc输出编译

4
4
Run Code Online (Sandbox Code Playgroud)

和g ++

1
4
Run Code Online (Sandbox Code Playgroud)

为什么会这样?我知道这不是编译器的事情,而是C和C++之间的区别,但是原因是什么?

c c++ gcc g++

21
推荐指数
2
解决办法
1135
查看次数

为什么C样式转换工作但reinterpret_cast不工作​​?

所以我有一个两个char数组

unsigned char v[2];
Run Code Online (Sandbox Code Playgroud)

我想将v [0]的值显示为0到255之间的数字但是

cout << v[0] << endl; //prints some garbage

cout << (void*)v[0] << endl; //prints the right thing but in hex
Run Code Online (Sandbox Code Playgroud)

所以我试过了

cout << (int)v[0] << endl;
Run Code Online (Sandbox Code Playgroud)

要么

printf("%d\n", v[0]);
Run Code Online (Sandbox Code Playgroud)

这显示了我想要的,但我完全不喜欢它.我根本不明白的是为什么这不起作用:

cout << reinterpret_cast<int>(v[0]) << endl; //compiler error
Run Code Online (Sandbox Code Playgroud)

c c++ casting reinterpret-cast

12
推荐指数
3
解决办法
1136
查看次数

为什么Libtool不想与静态库链接?

我想构建一个使用GNU Autotools使用ZipArchive的共享库,但我遇到了这个问题:

Warning: linker path does not have real file for library -lziparch.
I have the capability to make that library automatically link in when
you link to this library.  But I can only do this if you have a
shared version of the library, which you do not appear to have
because I did check the linker path looking for a file starting
with libziparch and none of the candidates passed a file format test
using a file magic. …

build-automation automake build autotools libtool

6
推荐指数
1
解决办法
1129
查看次数