Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard guarantees for aliases of integer types in C/C++? E.g.: Is "unsigned" always equal to "unsigned int"?

First question:

  • Is "unsigned" always the same as "unsigned int"?
  • Is "signed" always the same as "int"?
  • Is "short" always the same as "signed short"?
  • Is ...

Second question:

If a C/C++ standard specifies answers to above questions, what paragraphs are related to them?

like image 883
user1747883 Avatar asked Oct 15 '12 17:10

user1747883


People also ask

What is unsigned int in C?

An unsigned Integer means the variable can hold only a positive value. This format specifier is used within the printf() function for printing the unsigned integer variables. Syntax: printf(“%u”, variable_name);

What is unsigned long in CPP?

Unsigned long variables are extended size variables for number storage, and store 32 bits (4 bytes). Unlike standard longs unsigned longs won't store negative numbers, making their range from 0 to 4,294,967,295 (2^32 - 1).

What is unsigned short int C++?

Maximum value of unsigned short int in C++ It is the smallest (16 bit) integer data type in C++. Some properties of the unsigned short int data type are: Being an unsigned data type, it can store only positive values. Takes a size of 16 bits.


1 Answers

Yes, these are guaranteed. In C++11, see §7.1.6.2[dcl.type.simple]/table 10, which lists all of the simple type specifiers (and combinations thereof) and what they mean. For example, the table includes the following:

unsigned      => unsigned int
unsigned int  => unsigned int

signed        => int
signed int    => int
int           => int

C11 has a similar mapping in §6.7.2/2 (it's formatted differently, but otherwise it specifies the same groups of equivalent combinations, at least for all of the types common to C and C++).

like image 195
James McNellis Avatar answered Oct 16 '22 07:10

James McNellis