chappar
chappar

Reputation: 7505

character encoding in libc?

What is the character encoding expected in libc? For example, gethostname(char name, size_t namelen); takes char as argument. Is it expected that the name parameter be encoded in utf8(which keeps the ascii intact) or plain ascii or some other format?

Also does C mandates any character encoding scheme?

Upvotes: 4

Views: 1646

Answers (4)

qrdl
qrdl

Reputation: 34958

All string functions (except widechar ones) support only native charset, e.g. ASCII on Unix/Linux/Windows or EBCDIC on IBM mainframe/midrange computers.

Upvotes: 3

Bastien Léonard
Bastien Léonard

Reputation: 61683

You will probably have to use a third-party library, such as GLib. This lib is portable and very useful, it also provides regular expressions, data structures and more.

Upvotes: 0

JesperE
JesperE

Reputation: 64404

char should be a 7-bit compatible ASCII encoding (I can't find any definite reference on this though). The definition of wchar_t is left to the implementation, but the C standard requires that the characters from the C portable character set be the same. If I understand this correctly, then

char a = 'a';
wchar_t aw = L'a';
if (a == (char)aw) {
    // should be true
}

The standard does not say anything about UTF-8.

Upvotes: 0

dfa
dfa

Reputation: 116304

  • char uses ASCII
  • wchar_t is the standard C datatype for unicode

use and in order to deal with the wide characters.

Upvotes: 1

Related Questions