Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: What if pre-processor was moved to parser? Date: Thu, 16 Feb 2017 12:24:12 -0800 Organization: None to speak of Lines: 30 Message-ID: References: <11c906d6-9be0-44df-82b4-157fdba3b91c@googlegroups.com> <436a6e24-df32-45d9-b24e-c1e135c32c24@googlegroups.com> <8b49e198-86a5-45b4-ade7-a27ecb4f5e07@googlegroups.com> <7cc856f7-997e-496d-8ebf-ba413cb89d75@googlegroups.com> <7dc5b761-29bb-4244-aa99-ed20cbfa5fcd@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="4389ae8ca80d0229613347d13905988d"; logging-data="27355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CpwWpCl1+nzkBKrdNErC7" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:gU79ExaP3YTjWqM/NI9pPs8IoWk= sha1:e1NbzKjFRj1GP7u9F2HO4ZtKGII= Xref: csiph.com comp.lang.c:104032 supercat@casperkitty.com writes: > On Thursday, February 16, 2017 at 12:37:43 PM UTC-6, Keith Thompson wrote: >> supercat writes: >> [...] >> > The ability to compile a C program as C++ is only useful if the >> > resulting program will run with known semantics. There are some >> > constructs which have defined behavior in C but have no convenient >> > direct equivalent in C++. >> >> For example? > > I'm not a C++ expert by any means, but by my understanding it requires > that after one union member is used, any attempt to use another member > without first using placement new yields UB. Adding placement new might > not be a problem except that the Standard makes no guarantee about the > contents of any portion of the newly-selected member--even parts which > would share a Common Initial Sequence with the previously accessed member. C++ has the common initial sequence rule; C++11 9.2p19 [class.mem] and 9.3p1 [class.union]. I don't see anything in the C++ standard that permits writing to one member of a union and reading another, as C permits, but I could very easily be missing something. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"