Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ typeid中类型定义及其含义之间的差异(均衡)_C++_C_Types_Typeid - Fatal编程技术网

C++ typeid中类型定义及其含义之间的差异(均衡)

C++ typeid中类型定义及其含义之间的差异(均衡),c++,c,types,typeid,C++,C,Types,Typeid,unsigned int=unsigned int=signed int=signed signed long long int=signed long long=long long unsigned long long int=unsigned long long signed long int=signed long=long unsigned long int=unsigned long signed short int=signed short=short unsigned short

unsigned int
=
unsigned

int
=
signed int
=
signed

signed long long int
=
signed long long
=
long long

unsigned long long int
=
unsigned long long

signed long int
=
signed long
=
long

unsigned long int
=
unsigned long

signed short int
=
signed short
=
short

unsigned short int
=
unsigned short

signed char
=
char

我想知道上面提到的类型是C还是C++? 如果是这样的话,在相互平衡的同时又想知道它们的含义,它们还会是一样的吗?(例如:
typeid(带符号的长整型)
==
typeid(长整型)


回答:

有些类型相同,有些不同(=不相同):

  • 对于
    char
    ,添加
    signed
    unsigned
    总共会提供三种不同的类型
  • 对于
    short
    int
    long
    long
    表示有符号的
    ,添加该符号不起任何作用。添加未签名的
    将为您提供一组新的不同类型
  • unsigned
    short
    long
    long
    后面可以跟
    int
    ,但是如果
    int
    存在或不存在,则不会给出不同的类型
原则上,所有不同类型的
typeid
应该是不同的。这意味着模板和函数重载解析将把它们视为不同的类型,而例如传递
short
short int
都将调用相同的重载

据我所知,这些规则对于C和C++是相同的。如果我犯了一个错误,请告诉我,我是在一笔勾销

要检查这一点,可以结合使用进行编译时检查:

#include <type_traits>
using std::is_same;

static_assert(!is_same<char, signed char>(), "");
static_assert(!is_same<char, unsigned char>(), "");
static_assert(!is_same<unsigned char, signed char>(), "");


static_assert( is_same<short, signed short>(), "");
static_assert( is_same<int, signed int>(), "");
static_assert( is_same<long, signed long>(), "");
static_assert( is_same<long long, signed long long>(), "");

static_assert(!is_same<short, unsigned short>(), "");
static_assert(!is_same<int, unsigned int>(), "");
static_assert(!is_same<long, unsigned long>(), "");
static_assert(!is_same<long long, unsigned long long>(), "");

static_assert( is_same<unsigned int, unsigned>(), "");
static_assert( is_same<short int, short>(), "");
static_assert( is_same<long int, long>(), "");
static_assert( is_same<long long int, long long>(), "");

int main(){} // only included to make the program link
#包括
使用std::是相同的;
静态断言(!is_same(),“”);
静态断言(!is_same(),“”);
静态断言(!is_same(),“”);
静态断言(is_same(),“”);
静态断言(is_same(),“”);
静态断言(is_same(),“”);
静态断言(is_same(),“”);
静态断言(!is_same(),“”);
静态断言(!is_same(),“”);
静态断言(!is_same(),“”);
静态断言(!is_same(),“”);
静态断言(is_same(),“”);
静态断言(is_same(),“”);
静态断言(is_same(),“”);
静态断言(is_same(),“”);
int main(){}//仅用于创建程序链接

.

在C中没有
typeid
。同样在C中,
无符号int
绝对不是与
有符号int
相同的类型,并且
有符号char
不必与
char
相同,那么你的问题是什么?如果C中的类型不同,这个问题仍然适用
typeid
只是类型标识的运行时表现形式。一个在问题主体中明确说明的问题,顺便说一句,没有必要因为“不清楚你在问什么”而结束投票……相关:我不是在比较未签名和已签名。它们绝对不一样。我好像忘了添加一些新行,抱歉搞混了。顺便说一下,我问了C++的Type ID,有错误,比如“错误C2057:预期常量表达式”。无论如何,谢谢你澄清这一点。这里是一个比较: