Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #73713

Re: How to get a character consisting of multiple bytes into a string literal?

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: How to get a character consisting of multiple bytes into a string literal?
Date 2015-10-24 19:18 +0100
Organization A noiseless patient Spider
Message-ID <87bnbom8os.fsf@bsb.me.uk> (permalink)
References <n0gehd$p8k$1@solani.org>

Show all headers | View raw


Philipp Klaus Krause <pkk@spth.de> writes:

> Assuming my implementation supports the basic source character set, how
> can I create a string literal that contains multibyte character
> consisting of multiple bytes?
>
> I can't just write the character directly, since it is not in the basic
> source character set.
>
> And I don't think I can use an escape sequence: Verse 4 of section 6.4.5
> of the C11 standard states "The same considerations apply to each
> element of the sequence in a string literal as if it were in an integer
> character constant […]". I guess that means that 6.4.4.4, verse 10
> applies, and thus the value of the character constant has to be
> something representable in a char.

Sure, but each of the characters that make up the multibyte character
can be represented in an unsigned char (see 6.4.4.4 p9 and below).

> So is it possible to create a string literal containing a multibyte
> character of more than one byte when the implementation supports only
> the basic source character set as source character set?

u8"\xC2\xA3" (meaning "£") is fine from that point of view because
there's nothing in the source that is outside of the source character
set.  What's more, the values 0xC2 and 0xA3 can represented as values of
the type unsigned char as required by 6.4.4.4 p9.  (This requirement
applies even if char is signed.  I.e. you can write '\xC2' even when
0xC2 is not in the range of char itself.)

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to get a character consisting of multiple bytes into a string literal? Philipp Klaus Krause <pkk@spth.de> - 2015-10-24 19:18 +0200
  Re: How to get a character consisting of multiple bytes into a string literal? James Kuyper <jameskuyper@verizon.net> - 2015-10-24 14:06 -0400
    Re: How to get a character consisting of multiple bytes into a string literal? Philipp Klaus Krause <pkk@spth.de> - 2015-10-24 20:39 +0200
      Re: How to get a character consisting of multiple bytes into a string literal? James Kuyper <jameskuyper@verizon.net> - 2015-10-24 15:05 -0400
  Re: How to get a character consisting of multiple bytes into a string literal? Richard Damon <Richard@Damon-Family.org> - 2015-10-24 14:07 -0400
    Re: How to get a character consisting of multiple bytes into a string literal? James Kuyper <jameskuyper@verizon.net> - 2015-10-24 14:33 -0400
    Re: How to get a character consisting of multiple bytes into a string literal? Philipp Klaus Krause <pkk@spth.de> - 2015-10-24 21:30 +0200
  Re: How to get a character consisting of multiple bytes into a string literal? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-24 11:11 -0700
    Re: How to get a character consisting of multiple bytes into a string literal? Keith Thompson <kst-u@mib.org> - 2015-10-24 13:44 -0700
  Re: How to get a character consisting of multiple bytes into a string literal? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-24 19:18 +0100
  Re: How to get a character consisting of multiple bytes into a string literal? Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-24 11:57 -0700
    Re: How to get a character consisting of multiple bytes into a string literal? Philipp Klaus Krause <pkk@spth.de> - 2015-10-24 21:32 +0200
      Re: How to get a character consisting of multiple bytes into a string literal? James Kuyper <jameskuyper@verizon.net> - 2015-10-24 15:54 -0400
      Re: How to get a character consisting of multiple bytes into a string literal? Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-24 14:43 -0700
        Re: How to get a character consisting of multiple bytes into a string literal? Philipp Klaus Krause <pkk@spth.de> - 2015-10-25 10:38 +0100
          Re: How to get a character consisting of multiple bytes into a string literal? Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-25 10:05 -0700

csiph-web