Is C++20 'char8_t' the same as our old 'char'?How to convert a std::string to const char* or char*?When to use references vs. pointersCan a plain `char` possibly have trap values?Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsenum to string in modern C++11 / C++14 / C++17 and future C++20Does the C++ 14 memory model specify that a byte must have 8 bits?Has a std::byte pointer the same aliasing implications as char*?Does C++14 define the behavior of bitwise operators on the padding bits of unsigned int?Why is CHAR_BIT usually 8?What exactly can wchar_t represent?

Why should I "believe in" weak solutions to PDEs?

How do these cubesats' whip antennas work?

How do I get the =LEFT function in excel, to also take the number zero as the first number?

Do I have to buy filters to control contrast in multigrade papers?

Does this put me at risk for identity theft?

Unexpected route on a flight from USA to Europe

What does VB stand for?

How does the oscilloscope trigger really work?

Are children a reason to be rejected for a job?

Capacitors with a "/" on schematic

Does a jail-cell need a mezuzah?

What are these mathematical groups in U.S. universities?

What are the examples (applications) of the MIPs in which the objective function has nonzero coefficients for only continuous variables?

Does this smartphone photo show Mars just below the Sun?

Why don't the open notes matter in guitar chords?

Cobb-Douglas production function with expenditures rather than units

Does the Voyager team use a wrapper (Fortran(77?) to Python) to transmit current commands?

Is the Folding Boat truly seaworthy?

Why do private jets such as Gulfstream fly higher than other civilian jets?

Who is the god Ao?

Will a paper be retracted if a flaw in released software code invalidates its central idea?

Is it true that control+alt+delete only became a thing because IBM would not build Bill Gates a computer with a task manager button?

Is there a difference between 「目を覚ます」 and 「目覚める」

Why does putting a dot after the URL remove login information?



Is C++20 'char8_t' the same as our old 'char'?


How to convert a std::string to const char* or char*?When to use references vs. pointersCan a plain `char` possibly have trap values?Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsenum to string in modern C++11 / C++14 / C++17 and future C++20Does the C++ 14 memory model specify that a byte must have 8 bits?Has a std::byte pointer the same aliasing implications as char*?Does C++14 define the behavior of bitwise operators on the padding bits of unsigned int?Why is CHAR_BIT usually 8?What exactly can wchar_t represent?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








9















In the CPP reference documentation,



I noticed for char




The character types are large enough to represent any UTF-8 eight-bit
code unit (since C++14)




and for char8_t




type for UTF-8 character representation, required to be large enough
to represent any UTF-8 code unit (8 bits)




Does that mean both are the same type? Or does char8_t have some other feature?










share|improve this question





















  • 3





    Well, it's clear from looking that char8_t is an 8 bit type. Also, The signedness of char depends on the compiler and the target platform: the defaults for ARM and PowerPC are typically unsigned, the defaults for x86 and x64 are typically signed. while char8_t is always unsigned.

    – Elliott Frisch
    8 hours ago











  • " or does char8_t has an extra edge?" - what do you mean by that?

    – Neil Butterworth
    8 hours ago











  • I mean any other benefits

    – Pavan Chandaka
    7 hours ago











  • Rats. I was hoping you meant like the magic sword from The Sword and the Sorcerer.

    – user4581301
    7 hours ago


















9















In the CPP reference documentation,



I noticed for char




The character types are large enough to represent any UTF-8 eight-bit
code unit (since C++14)




and for char8_t




type for UTF-8 character representation, required to be large enough
to represent any UTF-8 code unit (8 bits)




Does that mean both are the same type? Or does char8_t have some other feature?










share|improve this question





















  • 3





    Well, it's clear from looking that char8_t is an 8 bit type. Also, The signedness of char depends on the compiler and the target platform: the defaults for ARM and PowerPC are typically unsigned, the defaults for x86 and x64 are typically signed. while char8_t is always unsigned.

    – Elliott Frisch
    8 hours ago











  • " or does char8_t has an extra edge?" - what do you mean by that?

    – Neil Butterworth
    8 hours ago











  • I mean any other benefits

    – Pavan Chandaka
    7 hours ago











  • Rats. I was hoping you meant like the magic sword from The Sword and the Sorcerer.

    – user4581301
    7 hours ago














9












9








9


1






In the CPP reference documentation,



I noticed for char




The character types are large enough to represent any UTF-8 eight-bit
code unit (since C++14)




and for char8_t




type for UTF-8 character representation, required to be large enough
to represent any UTF-8 code unit (8 bits)




Does that mean both are the same type? Or does char8_t have some other feature?










share|improve this question
















In the CPP reference documentation,



I noticed for char




The character types are large enough to represent any UTF-8 eight-bit
code unit (since C++14)




and for char8_t




type for UTF-8 character representation, required to be large enough
to represent any UTF-8 code unit (8 bits)




Does that mean both are the same type? Or does char8_t have some other feature?







c++ c++14 c++20






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago









Boann

38.6k13 gold badges93 silver badges123 bronze badges




38.6k13 gold badges93 silver badges123 bronze badges










asked 8 hours ago









Pavan ChandakaPavan Chandaka

5,8973 gold badges11 silver badges20 bronze badges




5,8973 gold badges11 silver badges20 bronze badges










  • 3





    Well, it's clear from looking that char8_t is an 8 bit type. Also, The signedness of char depends on the compiler and the target platform: the defaults for ARM and PowerPC are typically unsigned, the defaults for x86 and x64 are typically signed. while char8_t is always unsigned.

    – Elliott Frisch
    8 hours ago











  • " or does char8_t has an extra edge?" - what do you mean by that?

    – Neil Butterworth
    8 hours ago











  • I mean any other benefits

    – Pavan Chandaka
    7 hours ago











  • Rats. I was hoping you meant like the magic sword from The Sword and the Sorcerer.

    – user4581301
    7 hours ago













  • 3





    Well, it's clear from looking that char8_t is an 8 bit type. Also, The signedness of char depends on the compiler and the target platform: the defaults for ARM and PowerPC are typically unsigned, the defaults for x86 and x64 are typically signed. while char8_t is always unsigned.

    – Elliott Frisch
    8 hours ago











  • " or does char8_t has an extra edge?" - what do you mean by that?

    – Neil Butterworth
    8 hours ago











  • I mean any other benefits

    – Pavan Chandaka
    7 hours ago











  • Rats. I was hoping you meant like the magic sword from The Sword and the Sorcerer.

    – user4581301
    7 hours ago








3




3





Well, it's clear from looking that char8_t is an 8 bit type. Also, The signedness of char depends on the compiler and the target platform: the defaults for ARM and PowerPC are typically unsigned, the defaults for x86 and x64 are typically signed. while char8_t is always unsigned.

– Elliott Frisch
8 hours ago





Well, it's clear from looking that char8_t is an 8 bit type. Also, The signedness of char depends on the compiler and the target platform: the defaults for ARM and PowerPC are typically unsigned, the defaults for x86 and x64 are typically signed. while char8_t is always unsigned.

– Elliott Frisch
8 hours ago













" or does char8_t has an extra edge?" - what do you mean by that?

– Neil Butterworth
8 hours ago





" or does char8_t has an extra edge?" - what do you mean by that?

– Neil Butterworth
8 hours ago













I mean any other benefits

– Pavan Chandaka
7 hours ago





I mean any other benefits

– Pavan Chandaka
7 hours ago













Rats. I was hoping you meant like the magic sword from The Sword and the Sorcerer.

– user4581301
7 hours ago






Rats. I was hoping you meant like the magic sword from The Sword and the Sorcerer.

– user4581301
7 hours ago













1 Answer
1






active

oldest

votes


















15














char8_t is not the same as char. It behaves exactly the same as unsigned char though per [basic.fundamental]/9




Type char8_­t denotes a distinct type whose underlying type is unsigned char. Types char16_­t and char32_­t denote distinct types whose underlying types are uint_­least16_­t and uint_­least32_­t, respectively, in <cstdint>.




emphasis mine




Do note that since the standard calls it a distinct type, code like



std::cout << std::is_same_v<unsigned char, char8_t>;


will print 0(false), even though char8_t is implemented as a unsigned char. This is because it is not an alias, but a distinct type.




Another thing to note is that char can either be implemented as a signed char or unsigned char. That means it is possible for char to have the same range and representation as char8_t, but they are still separate types. char, signed char, unsigned char, and char8_t are the same size, but they are all distinct types.






share|improve this answer






















  • 2





    The bigger the C++ numbers, the more I enjoy simple ol' C...

    – Michael Dorgan
    7 hours ago






  • 4





    @MichaelDorgan But 98 is bigger than 17 and 98 was... not so fun to work with ;)

    – NathanOliver
    7 hours ago






  • 1





    @MichaelDorgan: Isn't the "compatibility" with C which increases complexity? as sign issue of char.

    – Jarod42
    7 hours ago






  • 2





    @MichaelDorgan in case you are unaware, C also has char16_t, char32_t and associated char/string literals and manipulation functions. (As well as char, unsigned char, signed char, int8_t and uint8_t of course)

    – M.M
    7 hours ago







  • 1





    For some definition of "exactly the same". A key feature of char8_t is that it doesn't alias everything under the sun.

    – T.C.
    7 hours ago










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57402464%2fis-c20-char8-t-the-same-as-our-old-char%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









15














char8_t is not the same as char. It behaves exactly the same as unsigned char though per [basic.fundamental]/9




Type char8_­t denotes a distinct type whose underlying type is unsigned char. Types char16_­t and char32_­t denote distinct types whose underlying types are uint_­least16_­t and uint_­least32_­t, respectively, in <cstdint>.




emphasis mine




Do note that since the standard calls it a distinct type, code like



std::cout << std::is_same_v<unsigned char, char8_t>;


will print 0(false), even though char8_t is implemented as a unsigned char. This is because it is not an alias, but a distinct type.




Another thing to note is that char can either be implemented as a signed char or unsigned char. That means it is possible for char to have the same range and representation as char8_t, but they are still separate types. char, signed char, unsigned char, and char8_t are the same size, but they are all distinct types.






share|improve this answer






















  • 2





    The bigger the C++ numbers, the more I enjoy simple ol' C...

    – Michael Dorgan
    7 hours ago






  • 4





    @MichaelDorgan But 98 is bigger than 17 and 98 was... not so fun to work with ;)

    – NathanOliver
    7 hours ago






  • 1





    @MichaelDorgan: Isn't the "compatibility" with C which increases complexity? as sign issue of char.

    – Jarod42
    7 hours ago






  • 2





    @MichaelDorgan in case you are unaware, C also has char16_t, char32_t and associated char/string literals and manipulation functions. (As well as char, unsigned char, signed char, int8_t and uint8_t of course)

    – M.M
    7 hours ago







  • 1





    For some definition of "exactly the same". A key feature of char8_t is that it doesn't alias everything under the sun.

    – T.C.
    7 hours ago















15














char8_t is not the same as char. It behaves exactly the same as unsigned char though per [basic.fundamental]/9




Type char8_­t denotes a distinct type whose underlying type is unsigned char. Types char16_­t and char32_­t denote distinct types whose underlying types are uint_­least16_­t and uint_­least32_­t, respectively, in <cstdint>.




emphasis mine




Do note that since the standard calls it a distinct type, code like



std::cout << std::is_same_v<unsigned char, char8_t>;


will print 0(false), even though char8_t is implemented as a unsigned char. This is because it is not an alias, but a distinct type.




Another thing to note is that char can either be implemented as a signed char or unsigned char. That means it is possible for char to have the same range and representation as char8_t, but they are still separate types. char, signed char, unsigned char, and char8_t are the same size, but they are all distinct types.






share|improve this answer






















  • 2





    The bigger the C++ numbers, the more I enjoy simple ol' C...

    – Michael Dorgan
    7 hours ago






  • 4





    @MichaelDorgan But 98 is bigger than 17 and 98 was... not so fun to work with ;)

    – NathanOliver
    7 hours ago






  • 1





    @MichaelDorgan: Isn't the "compatibility" with C which increases complexity? as sign issue of char.

    – Jarod42
    7 hours ago






  • 2





    @MichaelDorgan in case you are unaware, C also has char16_t, char32_t and associated char/string literals and manipulation functions. (As well as char, unsigned char, signed char, int8_t and uint8_t of course)

    – M.M
    7 hours ago







  • 1





    For some definition of "exactly the same". A key feature of char8_t is that it doesn't alias everything under the sun.

    – T.C.
    7 hours ago













15












15








15







char8_t is not the same as char. It behaves exactly the same as unsigned char though per [basic.fundamental]/9




Type char8_­t denotes a distinct type whose underlying type is unsigned char. Types char16_­t and char32_­t denote distinct types whose underlying types are uint_­least16_­t and uint_­least32_­t, respectively, in <cstdint>.




emphasis mine




Do note that since the standard calls it a distinct type, code like



std::cout << std::is_same_v<unsigned char, char8_t>;


will print 0(false), even though char8_t is implemented as a unsigned char. This is because it is not an alias, but a distinct type.




Another thing to note is that char can either be implemented as a signed char or unsigned char. That means it is possible for char to have the same range and representation as char8_t, but they are still separate types. char, signed char, unsigned char, and char8_t are the same size, but they are all distinct types.






share|improve this answer















char8_t is not the same as char. It behaves exactly the same as unsigned char though per [basic.fundamental]/9




Type char8_­t denotes a distinct type whose underlying type is unsigned char. Types char16_­t and char32_­t denote distinct types whose underlying types are uint_­least16_­t and uint_­least32_­t, respectively, in <cstdint>.




emphasis mine




Do note that since the standard calls it a distinct type, code like



std::cout << std::is_same_v<unsigned char, char8_t>;


will print 0(false), even though char8_t is implemented as a unsigned char. This is because it is not an alias, but a distinct type.




Another thing to note is that char can either be implemented as a signed char or unsigned char. That means it is possible for char to have the same range and representation as char8_t, but they are still separate types. char, signed char, unsigned char, and char8_t are the same size, but they are all distinct types.







share|improve this answer














share|improve this answer



share|improve this answer








edited 7 hours ago

























answered 8 hours ago









NathanOliverNathanOliver

111k19 gold badges172 silver badges251 bronze badges




111k19 gold badges172 silver badges251 bronze badges










  • 2





    The bigger the C++ numbers, the more I enjoy simple ol' C...

    – Michael Dorgan
    7 hours ago






  • 4





    @MichaelDorgan But 98 is bigger than 17 and 98 was... not so fun to work with ;)

    – NathanOliver
    7 hours ago






  • 1





    @MichaelDorgan: Isn't the "compatibility" with C which increases complexity? as sign issue of char.

    – Jarod42
    7 hours ago






  • 2





    @MichaelDorgan in case you are unaware, C also has char16_t, char32_t and associated char/string literals and manipulation functions. (As well as char, unsigned char, signed char, int8_t and uint8_t of course)

    – M.M
    7 hours ago







  • 1





    For some definition of "exactly the same". A key feature of char8_t is that it doesn't alias everything under the sun.

    – T.C.
    7 hours ago












  • 2





    The bigger the C++ numbers, the more I enjoy simple ol' C...

    – Michael Dorgan
    7 hours ago






  • 4





    @MichaelDorgan But 98 is bigger than 17 and 98 was... not so fun to work with ;)

    – NathanOliver
    7 hours ago






  • 1





    @MichaelDorgan: Isn't the "compatibility" with C which increases complexity? as sign issue of char.

    – Jarod42
    7 hours ago






  • 2





    @MichaelDorgan in case you are unaware, C also has char16_t, char32_t and associated char/string literals and manipulation functions. (As well as char, unsigned char, signed char, int8_t and uint8_t of course)

    – M.M
    7 hours ago







  • 1





    For some definition of "exactly the same". A key feature of char8_t is that it doesn't alias everything under the sun.

    – T.C.
    7 hours ago







2




2





The bigger the C++ numbers, the more I enjoy simple ol' C...

– Michael Dorgan
7 hours ago





The bigger the C++ numbers, the more I enjoy simple ol' C...

– Michael Dorgan
7 hours ago




4




4





@MichaelDorgan But 98 is bigger than 17 and 98 was... not so fun to work with ;)

– NathanOliver
7 hours ago





@MichaelDorgan But 98 is bigger than 17 and 98 was... not so fun to work with ;)

– NathanOliver
7 hours ago




1




1





@MichaelDorgan: Isn't the "compatibility" with C which increases complexity? as sign issue of char.

– Jarod42
7 hours ago





@MichaelDorgan: Isn't the "compatibility" with C which increases complexity? as sign issue of char.

– Jarod42
7 hours ago




2




2





@MichaelDorgan in case you are unaware, C also has char16_t, char32_t and associated char/string literals and manipulation functions. (As well as char, unsigned char, signed char, int8_t and uint8_t of course)

– M.M
7 hours ago






@MichaelDorgan in case you are unaware, C also has char16_t, char32_t and associated char/string literals and manipulation functions. (As well as char, unsigned char, signed char, int8_t and uint8_t of course)

– M.M
7 hours ago





1




1





For some definition of "exactly the same". A key feature of char8_t is that it doesn't alias everything under the sun.

– T.C.
7 hours ago





For some definition of "exactly the same". A key feature of char8_t is that it doesn't alias everything under the sun.

– T.C.
7 hours ago








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57402464%2fis-c20-char8-t-the-same-as-our-old-char%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу