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: To C or not to C++ Date: Tue, 16 Aug 2022 12:56:59 -0700 Organization: None to speak of Lines: 64 Message-ID: <87h72cc67o.fsf@nosuchdomain.example.com> References: <2868500762@darkrealms.ca> <87iln0owgr.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader01.eternal-september.org; posting-host="2024d2ee7c2b059636fda40068b25e8b"; logging-data="157775"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192TtfzdHda/QDWsrAc9P+n" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:1JsFrWrlAaWRQ5dJJ5mj4rt0lHU= sha1:p+WBe1OHs2Sd8oU7ZJNn0l43RTg= Xref: csiph.com comp.lang.c++:85960 Muttley@dastardlyhq.com writes: > On Tue, 16 Aug 2022 08:48:18 +0200 > David Brown wrote: >>On 15/08/2022 22:22, Bo Persson wrote: >>> On 2022-08-15 at 21:01, Muttley@dastardlyhq.com wrote: >>>> On Mon, 15 Aug 2022 06:16:23 -0000 (UTC) >>>> Juha Nieminen wrote: >>>>> Muttley@dastardlyhq.com wrote: >>>>>> Rubbish. I've got multi thousand line originally C programs which I've >>>>> happily >>>>>> compiled with C++ compilers in C++ mode due to a few minor C++ >>>>>> additions. >>>>> >>>>> I assume it's C89. Modern C is more unlikely to be compilable as C++ >>>>> as-is >>>>> (for example because of out-of-order designated initializers, >>>>> 'restrict', >>>>> and so on). Even some completely standard-legal C89 won't compile as >>>>> C++, >>>>> such as: >>>>> >>>>>   char *str = "hello"; >>>>> >>>>> (which is 100% valid standard C, but not valid C++.) >>>> >>>> Both clang and gcc will compile it but with a warning. >>>> >>> >>> And the warning says that it *is* valid?! >> >>No, the warning tells you that it is /invalid/ : >> >> warning: ISO C++ forbids converting a string constant to 'char*' >> [-Wwrite-strings] >> >>Muttley must have forgotten to mention that. > > I didn't forget anything. The fact is both those compilers will compile it. > A warning is a warning, its not an error. As you probably already know, the standard does not require a conforming compiler to reject anything unless there's a #error directive that survives preprocessing. (At least that's the rule for C; I haven't found wording in the C++ standard that requires rejecting a program with a #error directive.) For any other violation of the language rules, all the standard requires is a diagnostic, which can be a non-fatal warning. You're right, it's not correct to say that `char *str = "hello";` "won't compile as C++". A conforming compiler must diagnose it, but after doing so it may either accept it or reject it. The warning quoted above satisifies the standard's requirement for a diagnostic. A C++ program containing that declaration is *ill-formed*. The distinction between a warning and an error is less significant than you imply it is. I'd say the content of the warning was relevant. You chose to omit it for some reason. -- 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 */