Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: longer 'char literals' meaning in c Date: Thu, 30 Apr 2020 15:30:42 -0700 Organization: None to speak of Lines: 45 Message-ID: <874kt061yl.fsf@nosuchdomain.example.com> References: <9bf151f2-e3f8-488b-bf10-9ba136d23a4f@googlegroups.com> <87sggk665l.fsf@nosuchdomain.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="3a8562cb4f6a88758e42aeb600e70f1e"; logging-data="12030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+H0Q40mB4CY3EiFFpwemhJ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:ClLqB9S8XmHD9oEggwLIvqyx8Jw= sha1:sFYxKZNzpVKOZHsBJoMQwSu4sq8= Xref: csiph.com comp.lang.c:151891 Bart writes: > On 30/04/2020 22:00, Keith Thompson wrote: >> Bart writes: >>> C with 32-bit ints also limit the length to 4 characters. >> >> No it doesn't. gcc does print a warning for 'ABCDE': >> >> warning: character constant too long for its type >> >> but that's not a required diagnostic, just something that gcc chooses to >> warn about. It prints a different warning for *any* multi-character >> constant: >> >> warning: multi-character character constant [-Wmultichar] >> >> That's not a required diagnostic either. Both 'ABCD' and 'ABCDE' >> are conforming, with implementation-defined (and not necessarily >> distinct) values of type int. A compiler that rejects 'ABCDE' >> because it won't fit in an int would be non-conforming. (gcc gives >> 'ABCDE' the same value as 'BCDE'.) > > So it limits the length to 4 characters as I said. That it ends up > with 'BCDE' rather than 'ABCD' is because the 'E' is the least > significant byte of the int, as gcc does it, and the 'A' would have > occupied bit 33 upwards. When you said it limits the length to 4 characters, I took that to mean that 'ABCDE' would be invalid (and you did show a warning). There is no specified limit on the number of characters in a multi-character constant. (A compiler can limit logical source lines to 4095 characters, but is not required to impose any limit at all.) [...] > For example when was L'...' introduced'? ANSI C, 1989 (or likely earlier in some implementations). [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */