Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 118069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:26:11+00:00 2026-05-11T03:26:11+00:00

The code below compiles, but has different behavior for the char type than for

  • 0

The code below compiles, but has different behavior for the char type than for the int types.

In particular

   cout << getIsTrue< isX<int8>::ikIsX  >() << endl;    cout << getIsTrue< isX<uint8>::ikIsX  >() << endl;    cout << getIsTrue< isX<char>::ikIsX  >() << endl; 

result in 3 instantiations of templates for three types: int8, uint8 and char. What gives?

The same is not true for ints: int and uint32 which result in the same template instantiation, and signed int another.

The reason seems to be that C++ sees char, signed char and unsigned char as three different types. Whereas int is the same as a signed int. Is this right or am I missing something?

#include <iostream>  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 <typename T> struct isX {    typedef typename T::ikIsX ikIsX; };   // This  int==int32 is ambiguous //template <>            struct isX<int  >    { typedef FalseType ikIsX; };  // Fails template <>            struct isX<int32  >  { typedef FalseType ikIsX; }; template <>            struct isX<uint32 >  { typedef FalseType ikIsX; };   // Whay isn't this ambiguous? char==int8 template <>            struct isX<char  >  { typedef FalseType ikIsX; }; template <>            struct isX<int8  >  { typedef FalseType ikIsX; }; template <>            struct isX<uint8 >  { typedef FalseType ikIsX; };   template <typename T> bool getIsTrue(); template <>           bool getIsTrue<TrueType>() { return true; } template <>           bool getIsTrue<FalseType>() { return false; }  int main(int, char **t ) {    cout << sizeof(int8) << endl;  // 1    cout << sizeof(uint8) << endl; // 1    cout << sizeof(char) << endl;  // 1     cout << getIsTrue< isX<int8>::ikIsX  >() << endl;    cout << getIsTrue< isX<uint8>::ikIsX  >() << endl;    cout << getIsTrue< isX<char>::ikIsX  >() << endl;     cout << getIsTrue< isX<int32>::ikIsX  >() << endl;    cout << getIsTrue< isX<uint32>::ikIsX  >() << endl;    cout << getIsTrue< isX<int>::ikIsX  >() << endl;  } 

I’m using g++ 4.something

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:26:12+00:00Added an answer on May 11, 2026 at 3:26 am

    Here is your answer from the standard:

    3.9.1 Fundamental types [basic.fundamental]

    Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set. If a character from this set is stored in a character object, the integral value of that character object is equal to the value of the single character literal form of that character. It is implementation-defined whether a char object can hold negative values. Characters can be explicitly declared unsigned or signed. Plain char, signed char, and unsigned char are three distinct types. A char, a signed char, and an unsigned char occupy the same amount of storage and have the same alignment requirements (basic.types); that is, they have the same object representation. For character types, all bits of the object representation participate in the value representation. For unsigned character types, all possible bit patterns of the value representation represent numbers. These requirements do not hold for other types. In any particular implementation, a plain char object can take on either the same values as a signed char or an unsigned char; which one is implementation-defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 108k
  • Answers 108k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As well as unit testing, it can be good to… May 11, 2026 at 9:17 pm
  • Editorial Team
    Editorial Team added an answer It's actually: -(IBAction) onClick1: (id) sender { NSLog(@"User clicked %@",… May 11, 2026 at 9:17 pm
  • Editorial Team
    Editorial Team added an answer Static classes (methods) do not necessarily have to be avoided… May 11, 2026 at 9:17 pm

Related Questions

I have a generic method which has two generic parameters. I tried to compile
In his excellent book, CLR Via C#, Jeffrey Richter said that he doesn't like
The code I'm working with has its own smart pointer implementation which does simple
For a long time I've been trying different languages to find the feature-set I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.