Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the standard guarantee that uint8_t, int8_t, and char are all unique types?

It seems the following is guaranteed to pass (asked already here):

#include <type_traits>
static_assert(!std::is_same_v<char, signed char>);
static_assert(!std::is_same_v<char, unsigned char>);

To quote cppreference

[char] has the same representation and alignment as either signed char or unsigned char, but is always a distinct type

Is it also guaranteed that int8_t and uint8_t are defined in terms of the explicitly signed types not defined in terms of char, and therefore also form a set of 3 distinct types with char?

#include <cstdint>
#include <type_traits>
static_assert(!std::is_same_v<char, int8_t>);
static_assert(!std::is_same_v<char, uint8_t>);
like image 482
Eric Avatar asked Aug 29 '19 07:08

Eric


1 Answers

On your first point, yes, char, signed char, and unsigned char must always be distinct types.

On the second point, int8_t and uint8_t might be or might not be the same type as a char (or its signed or unsigned variants); i.e. there is no guarantee for or against.

like image 161
Bathsheba Avatar answered Oct 30 '22 20:10

Bathsheba