Re:Confession Of A C/C++ Programmer (2017)
by flohofwoe on Monday January 25, 2021 @11:13AM
(#25904850)
The common subset of C and C++ is different enough from "idiomatic" C and C++ that it almost can be called a separate "C/C++" language ;)
[ Parent
| on HN ]
Re:Confession Of A C/C++ Programmer (2017)
by zabzonk on Monday January 25, 2021 @11:49AM
(#25905371)
The common subset should probably be called something like "better C" - it won't be able to use any major (or many minor) C++ features. Basically, it will be ANSI C (give or take). Noticeably, the code for the 2nd Ed of The C Programming Language was tested using a C++ compiler, not a C compiler
Re:Confession Of A C/C++ Programmer (2017)
by flohofwoe on Monday January 25, 2021 @05:35PM
(#25909898)
The common C/C++ subset is an outdated and non-standard C though. For instance standard-conforming C++ compilers cannot compile C99 code and onward, they're stuck at a non-standard C version that would roughly be C95, minus some things that are valid C but not valid C++.
Re:Confession Of A C/C++ Programmer (2017)
by pjmlp on Tuesday January 26, 2021 @02:46AM
(#25913489)
They can compile more C11 code than C99, thanks to the stuff dropped in C11.
They also support most of the C standard library additions.
As of C++20, the biggest difference is that designated initializers must follow field declaration order, restrict and _Generic aren't supported, and the type safety semantics are stronger.
Re:Confession Of A C/C++ Programmer (2017)
by flohofwoe on Tuesday January 26, 2021 @04:30AM
(#25913960)
There's also a handful of small differences like this, e.g. in C it's possible to construct a value and take the address for a pointer argument right in the function call:
func(&(bla_t){ .x=1, .y=2 });
This is completely valid C, but invalid C++ (C++ has references as "workaround" for such adhoc-constructed parameters which shouldn't be passed by value).