Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Are there any conformant C compilers? Date: Fri, 02 Sep 2022 11:50:58 -0700 Organization: None to speak of Lines: 61 Message-ID: <87bkrxhap9.fsf@nosuchdomain.example.com> References: <87v8q8qygb.fsf@bsb.me.uk> <87bks0pdex.fsf@bsb.me.uk> <871qswi3nc.fsf@nosuchdomain.example.com> <87wnaoghlj.fsf@nosuchdomain.example.com> <87sflahhkp.fsf@nosuchdomain.example.com> <87fsh9iz25.fsf@bsb.me.uk> <11d1020d-144d-4da0-88c1-3d56b4160c2an@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="de35b96096a59cc6da75511c8e166749"; logging-data="2742406"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tqW/Cejoz7RS01m3j9ZK0" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:z2bRN6NxDkvHTmlL+78suK9r5+g= sha1:7n3NZR49OmoDuLy/oSUbjZV64/c= Xref: csiph.com comp.lang.c:167437 Thiago Adams writes: > On Friday, September 2, 2022 at 1:53:06 PM UTC-3, Bart wrote: >> On 02/09/2022 16:19, Ben Bacarisse wrote: >> > Bart writes: >> > >> >>>> The only other actual literal is a string. >> >>> How about compound literals? >> >> >> >> The 'literal' in those is just a term somebody decided use. >> > >> > They are literals because they describe a specific value in the source >> > code. The value is "literally" in the source. >> > >> >> (Elsewhere I would call them constructors.) >> > >> > Sure. And the ASCII digit 1 is a constructor for an int value. And a " >> > optionally followed by characters and another " is a constructor for a >> > char array object. >> > >> > Both terms work, but the one C has chosen is "literal". >> > >> Some constructors are special: >> >> 123456 >> 123.456 >> "abcdef" >> 'A' >> >> because they can /only/ comprise values known at compile-time. These I >> like to call literals. > > Compound literals also are values known at compile time. Not necessarily. A compound literal at block scope can contain non-constant expressions. struct foo { int a; int b; }; struct foo obj; obj = (struct foo) { .a = rand(), .b = rand() }; > For instance: > ((int []){1, 2, 3}) > or > ((struct X { int i ; } ){.i = 2}) > > ( > by the way, in C23 compound literal can have storage > specifier, static constexpr.. > Like > ((static int []){1, 2, 3}) > ) That's handy. It means that you can write a compound literal at block scope whose associated object doesn't vanish at the end of the block. With `static`, you can return a pointer to it. It gives you behavior more similar to string literals. -- 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 */