linear-cpp icon indicating copy to clipboard operation
linear-cpp copied to clipboard

What is a char?

Open archer884 opened this issue 8 years ago • 1 comments

With the proliferation (if I think of a word that sounds more like how a disease spreads, I'll edit this) of unicode, it's become pretty common for new languages to make allowances for unicode strings, or to use unicode strings natively. In both cases, a character is a pretty strange type--and often we're talking about something that is 16 or 32 bits wide. This isn't the case in C++. I actually don't know off the top of my head what a character in C++ is (I think it's an 8-bit value representing... ascii?), so I think that (for experienced programmers, anyway) it might be good to mention that in passing.

archer884 avatar Aug 30 '16 21:08 archer884

A char is a byte -- that is, 8 bit. However, by way of ASCII, "character" did, in fact, inspire the naming of "char."

The more important point of confusion is the size of int / uint, because they are only defined as at least values, leaving compilers with the freedom to determine the sizes at will. (i.e. int can be 4 bytes, but also 2 bytes; sometimes it's also a 64bit value -- 8 bytes. That way you are nearly always forced to determine sizes using sizeof.)

19h avatar Aug 06 '17 11:08 19h