"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > The following are English question and answer titles generated based on the article content you provided: Why does `char` behave differently from integer types in template instantiation when comparing `char`, `signed char`, and `unsigned char`?

The following are English question and answer titles generated based on the article content you provided: Why does `char` behave differently from integer types in template instantiation when comparing `char`, `signed char`, and `unsigned char`?

Published on 2024-11-03
Browse:559

以下是根据您提供的文章内容生成的英文问答类标题:

Why does `char` behave differently from integer types in template instantiation when comparing `char`, `signed char`, and `unsigned char`?

differences in behavior between char, signed char and unsigned char

The code below compiles successfully, but char behaves differently than integer types.

cout ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() 

The result is three instantiation patterns for three types: int8, uint8 and char. Why does this happen?

The same is not true for integers: int and uint32 result in one pattern instantiation, and signed int results in another.

The reason is probably because C treats char , signed char and unsigned char as three different types. While int is the same as signed int. Is this true, or am I missing something?

#include 

using namespace std;

typedef   signed char       int8;
typedef unsigned char      uint8;
typedef   signed short      int16;
typedef unsigned short     uint16;
typedef   signed int        int32;
typedef unsigned int       uint32;
typedef   signed long long  int64;
typedef unsigned long long uint64;

struct TrueType {};
struct FalseType {};

template 
struct isX
{
   typedef typename T::ikIsX ikIsX;
};


// Это  int==int32 неоднозначно
//template  bool getIsTrue();
template ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() 

I use g 4.something

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3