5 ms·
> C++ is a superset of C, and that virtually any legal C program is a legal C++ program. This is not true. One example, void* pointers are not automatically co
by minipci1321 9y ago
> C++ is a superset of C, and that virtually any legal C program is a legal C++ program.
This is not true. One example, void* pointers are not automatically converted to "narrower" types in C++ as they are in C.
- EpicEng 9y ago>"virtually" There are differences, but they are few and far between.
- minipci1321 9y agoThat does disqualify C++ as the __superset__ of C doesn't it?
- saghm 9y agoSyntactically, C++ is a superset of C though, right? I can't think of any C syntax that's not valid C++, but I'm not exactly am expert in either
- minipci1321 9y ago> I can't think of any C syntax that's not valid C++, enum toto { a = 1 }; enum toto b = 1; Fixing versions of both standards could bring in more examples (like trailing comma in enums and use of the names reserved in C++, by the C code). Overall, ironically, as typing is stronger in C++ (which I agree is a non-syntactic change), poor C code (using lots of unjustified casts), will require less modifications to be compiled as C++.
- saghm 9y agoThanks for the example!
- minipci1321 9y ago> I can't think of any C syntax that's not valid C++, enum toto { a = 1 }; enum toto b = 1; Fixing versions of both standards could bring in more examples (like trailing comma in enums and use of the names reserved in C++, by the C code). Overall, ironically, as typing is stronger in C++ (which I agree is a non-syntactic change), poor C code (using lots of unjustified casts), will require less modifications to be compiled as C++.
- minipci1321 9y ago> I can't think of any C syntax that's not valid C++, enum toto { a = 1 }; enum toto b = 1; Fixing versions of both standards could bring in more examples (like trailing comma in enums and use of the names reserved in C++, by the C code). Overall, ironically, as typing is stronger in C++ (which I agree is a non-syntactic change), poor C code (using lots of unjustified casts), will require less modifications to be compiled as C++.
- bstamour 9y agoC supports variable-length stack-allocated arrays, while C++ doesn't. So code like void f() { int x; scanf("%d", &x); // read from user int numbers[x]; // dynamic } is legal C, but not C++. Also, the C "restrict" keyword doesn't exist in C++ either. Add in C's looser typing rules regarding conversions, and C and C++ are basically sibling languages at this point. Their common ancestor language being K&R-era C.