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: Fri, 12 Aug 2022 12:09:51 -0700 Organization: None to speak of Lines: 43 Message-ID: <87pmh5e0sg.fsf@nosuchdomain.example.com> References: <2868500762@darkrealms.ca> <87iln0owgr.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="05d9063ffd9b5feaccaae838e92706c7"; logging-data="2715119"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dwjMVSkK9T7T+up5vceMK" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:vPjjIeGPmxqbvZkYkdgg1t728jg= sha1:cfJxpMiSF2UWMqoJGz0I15TcmGQ= Xref: csiph.com comp.lang.c++:85895 Muttley@dastardlyhq.com writes: > On Fri, 12 Aug 2022 12:12:19 -0000 (UTC) > Juha Nieminen wrote: >>Muttley@dastardlyhq.com wrote: >>>>Sure, but "C/C++" isn't a good way to say that. You never see "C/Java". >>> >>> Last time I looked you couldn't compile C with a java compiler. >> >>I'm somewhat certain that if you search enough you'll find a polyglot >>program that will compile both as C and Java. > > I rather doubt that. You could #define "class", some class name and "public" > to nothing but you're not going to be able to do much about the extra curly > brackets around main() and C compilers don't like that. > >>C is not 100% compatible with C++ either, so any "C code" that you might >>write that just happens to compile and work the same in C++ is technically >>speaking a C/C++ polyglot. (Sure, it's infinitely easier to write a C/C++ >>polyglot program than eg. a C/Java one, but still. C is not a pure subset >>of C++.) > > So what. Its enough of a subset to work 99.9% of the time. 99.9%? I doubt it. And why would you want to? Do you really write code *and then* decide whether you're going to compile it with a C compiler or a C++ compiler? C++ has facilities for interfacing with C code. There are rare valid reasons to write code that can compile as both C and C++ with the same semantics (and you have to exercise some care to avoid a few pitfalls where the same code can have different meanings). Much valid C code is valid C++ code. Most valid C code can be made into valid C++ code without a lot of effort (casting malloc, for example). Very little *good* C code is good C++ code. -- 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 */