Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How to get a character consisting of multiple bytes into a string literal? Date: Sat, 24 Oct 2015 13:44:49 -0700 Organization: None to speak of Lines: 31 Message-ID: References: <337f4b24-de29-41fa-ac20-0f58bf0e2d5f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="6596"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182/xT9I1jSgRKFfg9dv/r4" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:e/DSJJR6+javPA+cQ761TVeB59Y= sha1:1NK9EQR3GW1i+pdVRIw6AjE8f9U= Xref: csiph.com comp.lang.c:73737 Malcolm McLean writes: > On Saturday, October 24, 2015 at 6:18:56 PM UTC+1, Philipp Klaus Krause wrote: >> Assuming my implementation supports the basic source character set, how >> can I create a string literal that contains multibyte character >> consisting of multiple bytes? >> > Depends how you want to pass the data about. > > You can use the L prefix L"Wide chars"; to create a 16-bit string > literal. A string literal prefixed with L represent a sequence of wchar_t elements. wchar_t is typically 16 bits on Windows, but 32 bits on Unix-like systems. > Or you use use UTF-8 and write char *str = "utf-8 is ascii > with extended characters like aleph (\xe2\x84\xb5)"; Or, if your compiler supports it, u8"..." is a UTF-8 string literal, u"..." represents a sequence of char16_t, and U"..." represents a sequence of char32_t. These are new in C11. > The second method is OK for a few embedded non-English characters, > but not human-maintainable for flowing text, so realistically you'll > need a tool to generate the literals. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"