Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C standard : Character set and string encoding specification

Tags:

People also ask

What is the standard for encoding characters?

Unicode. Unicode is a universal character set, ie. a standard that defines, in one place, all the characters needed for writing the majority of living languages in use on computers. It aims to be, and to a large extent already is, a superset of all other character sets that have been encoded.

What character set does C use?

ASCII ValuesAll the character sets used in the C language have their equivalent ASCII value. The ASCII value stands for American Standard Code for Information Interchange value. It consists of less than 256 characters, and we can represent these in 8 bits or even less.

What are the 3 types of character encoding?

There are three different Unicode character encodings: UTF-8, UTF-16 and UTF-32.

What is the difference between character set and encoding?

A character set is a list of characters whereas an encoding scheme is how they are represented in binary. This is best seen with Unicode. The encoding schemes UTF-8, UTF-16 and UTF-32 use the Unicode character set but encode the characters differently. ASCII is a character set and encoding scheme.


I found the C standard (C99 and C11) vague with respect to character/string code positions and encoding rules:

Firstly the standard defines the source character set and the execution character set. Essentially it provides a set of glyphs, but does not associate any numerical values with them - So what is the default character set?

I'm not asking about encoding here but just the glyph/repertoire to numeric/code point mapping. It does define universal character names as ISO/IEC 10646, but does it say that this is the default charset?

As an extension to the above - I couldn't find anything which says what characters the numeric escape sequences \0 and \x represent.

From the C standards (C99 and C11, I didn't check ANSI C) I got the following about character and string literals:

 +---------+-----+------------+----------------------------------------------+
 | Literal | Std | Type       | Meaning                                      |
 +---------+-----+------------+----------------------------------------------+
 | '...'   | C99 | int        | An integer character constant is a sequence  |
 |         |     |            | of one or more multibyte characters          |
 | L'...'  | C99 | wchar_t    | A wide character constant is a sequence of   |
 |         |     |            | one or more multibyte characters             |
 | u'...'  | C11 | char16_t   | A wide character constant is a sequence of   |
 |         |     |            | one or more multibyte characters             |
 | U'...'  | C11 | char32_t   | A wide character constant is a sequence of   |
 |         |     |            | one or more multibyte characters             |
 | "..."   | C99 | char[]     | A character string literal is a sequence of  |
 |         |     |            | zero or more multibyte characters            |   
 | L"..."  | C99 | wchar_t[]  | A wide string literal is a sequence of zero  |
 |         |     |            | or more multibyte characters                 | 
 | u"..."  | C11 | char16_t[] | A wide string literal is a sequence of zero  |
 |         |     |            | or more multibyte characters                 | 
 | U"..."  | C11 | char32_t[] | A wide string literal is a sequence of zero  |
 |         |     |            | or more multibyte characters                 | 
 | u8"..." | C11 | char[]     | A UTF-8 string literal is a sequence of zero |
 |         |     |            | or more multibyte characters                 | 
 +---------+-----+------------+----------------------------------------------+

However I couldn't find anything about the encoding rules for these literals. UTF-8 does seem to hint UTF-8 encoding, but I don't think it's explicitly mentioned anywhere. Also, for the other types is the encoding undefined or implementation dependent?

I'm not to familiar with the UNIX specification. Does the UNIX specification specify any additional constraint(s) to these rules?

Also if anyone can tell me what charset/encoding scheme is used by GCC and MSVC that would also help.