Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: Differences between C and C++ Date: Wed, 27 Jul 2022 11:11:39 -0700 Organization: None to speak of Lines: 39 Message-ID: <878roexw6c.fsf@nosuchdomain.example.com> References: <87k081tbjm.fsf@bsb.me.uk> <87r129yp5a.fsf@nosuchdomain.example.com> <87wnbzya2e.fsf@nosuchdomain.example.com> <3526ff38-3c29-45ab-a390-7bc6e6354164n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="4cade4b69894ce75454f6fba9132da96"; logging-data="2725243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zpXtCiBuieK220bnLWVcW" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:3xMlNZG8ziMMQBHnYe9MgE+vThg= sha1:PXGEBaq+qvNTUhZCpENBtxIlyEM= Xref: csiph.com comp.lang.c++:85698 Muttley@dastardlyhq.com writes: > On Wed, 27 Jul 2022 01:56:23 -0700 (PDT) > =?UTF-8?B?w5bDtiBUaWli?= wrote: >>On Wednesday, 27 July 2022 at 10:52:22 UTC+3, Mut...@dastardlyhq.com wrote: >>> >Most C++ compilers are non-conforming by default, quietly accepting >>> >extensions that are incompatible with the standard. All conforming C++ >>> >compilers provide a way to issue all required diagnostics. >>> I'm aware of all this. My point is why are some C semantics considered >>> compilable (albeit with warnings) but the original example of &(struct s){1} >> >>> isn't and causes an error even though its perfectly legal in C. >> >>It is because while the compilers implemented extension of supporting >>compound literals almost like in C, the result in those extensions is >>temporary whose lifetime will last only to end of full-expression. Taking > > The expressions lifetime - and hence the temporary shouldn't end until the > function being called returns. It should remain on the stack of the calling > function which is probably what happens in C. > >>Why they did not implement the semantics fully like in C is because they >>used it like kind of alternative syntax sugar to list-initialization. Since >>C++14 however they can not heap-allocate initializer-lists (and did not >>do it even before C++14). So the compound literal extension is temporary >>for ease of implementation. Some of compilers that do it are open source >>so if you want you can perhaps implement more close to C extension >>to those. > > Why? Since they're also already C compilers the code to do it already exists > inside them and is probably a case of setting an internal flag to call it. Because they're not also already C compilers. A C and C++ compiler might share the same backend and a lot of other infrastructure, but the front ends are going to be separate. -- 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 */