Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: How to write wide char string literals? Date: Fri, 02 Jul 2021 02:31:24 -0700 Organization: None to speak of Lines: 68 Message-ID: <87sg0x83kj.fsf@nosuchdomain.example.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="4a9cda081a23edd708b9033b2d6874e1"; logging-data="22441"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vLF+y9zK6UGMfsUQqjob4" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:i9GA+3rc+9E8K7Q6Qnd6I4w0/Iw= sha1:ljUjtze0Av9jmS1bi3cq4NAbVVc= Xref: csiph.com comp.lang.c++:80620 Ralf Goertz writes: [...] > I created this file b.cc: > > int main() { > return 0; > } > > using vi with > > :set fileencoding=utf16 > :set bomb > > Then > > ~/c> file b.cc > b.cc: C source, Unicode text, UTF-16, big-endian text > > or > > ~/c> od -h b.cc > 0000000 fffe 6900 6e00 7400 2000 6d00 6100 6900 > 0000020 6e00 2800 2900 2000 7b00 0a00 2000 2000 > 0000040 2000 2000 7200 6500 7400 7500 7200 6e00 > 0000060 2000 3000 3b00 0a00 7d00 0a00 > 0000074 > > where you can see the BOM fffe. Feeding this to gcc (or g++) you get: > > ~/c> gcc b.cc > b.cc:1:1: error: stray ‘\376’ in program > 1 | �� i n t m a i n ( ) { > | ^ > b.cc:1:2: error: stray ‘\377’ in program > 1 | �� i n t m a i n ( ) { > | ^ > b.cc:1:3: warning: null character(s) ignored > 1 | �� i n t m a i n ( ) { > | ^ > b.cc:1:5: warning: null character(s) ignored > > etc. > > How does that qualify as “gcc honoring the BOM”? On my system, gcc doesn't handle UTF-16 at all, with or without a BOM. (I don't know whether there's a way to configure it to do so.) It does handle UTF-8 with or without a BOM. $ file b.cpp b.cpp: C source, UTF-8 Unicode (with BOM) text $ cat b.cpp int main() { } $ hd b.cpp 00000000 ef bb bf 69 6e 74 20 6d 61 69 6e 28 29 20 7b 20 |...int main() { | 00000010 7d 0a |}.| 00000012 $ gcc -c b.cpp $ gcc 9.3.0 on Ubuntu 20.04. (There is, of course, no point in going back to ancient versions of gcc.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */