4 ms·
What C features can you not realistically use from C++?
by nly 7mo ago
What C features can you not realistically use from C++?
- anthk 7mo agoPeople shoudld realize that since long ago C and C++ are not sub/supersets, but interesecting sets.
- 201984 7mo agoC11 atomics, C11 threads, variable length arrays, safely reading from an inactive union member, designated array initializers, compound struct literals, implicitly converting a void pointer to a typed one, and the list goes on.
- pjmlp 7mo agoIndeed, and some of those, thankfully as C++ is TypeScript for C.
- nly 7mo agoC++ has its own atomics, threads etc. And variable length array's work just fine in C++ in both clang and GCC. C++ also has it's own designated initializer like syntax.
- 201984 7mo ago>C++ has its own atomics, threads etc. It does indeed, but they are not compatible and at least the C atomics cannot be used from C++. >C++ also has it's own designated initializer like syntax. One that is far more limited. This is valid C, but not C++. struct bar { int a; int b; }; struct bar tmp = { .b = 0, .a = 0, };
- flohofwoe 7mo agoAny language feature added in C99 and later. In GCC and Clang it's quite relaxed since their C++ frontends pull in a couple of modern C features as non-standard C++ extensions, but MSVC has a strict separation between the C++ and C frontend and doesn't allow this sort of 'cross-pollution'. As a quick example, this C99 code block has at least 4 features that don't work in C++: https://github.com/floooh/sokol-samples/blob/91bd8c6f9f52149211d5508703cc805b67bfa399/sapp/texcube-sapp.c#L124-L140 https://github.com/floooh/sokol-samples/blob/91bd8c6f9f52149... - taking the address of an adhoc-created struct in a function call - random array access in struct initialization - designator chaining in struct initialization - designators can be out-of-order in C but not C++ ...also using unions as different views on the same memory is actually useful sometimes.
- nly 7mo agoNothing of value was lost