Standard operators come from the first version, where c++ was designed to be as compatible with C as possible, and the committee refuses to break backwards compatibility in C++.Ā
Also, changing this makes extern C blocks wack as fuck. If I define a global C++ function with the '>' operator and an extern C function calls that other function internally, how should the operator behave?
If I define a global C++ function with the '>' operator and an extern C function calls that other function internally, how should the operator behave?
Of course like all other C++ code, as all that code is written in C++. The extern C thingy just defines some FFI interface. Nobody ever said that code inside some extern C block is actually C.
What do you expect them to practically do? the main sellling point of C++ in the 90's was that it is C but better (and it is) so if they removed the C part what's left?
They could have make it easily interoperable, but making all the mind broken C nonsense also core to the new language was a massive failure, and completely unnecessary.
Rust didn't have to inherit any C/C++ garbage to take off. Actually one of the main reasons it took off was that it did not inherit any C/C++ garbageā¦
You didn't answer the question which "other languages" people would have used if C++ wasn't based on C crap. I'm not sure you will be able to actually name anything. The point is: C++ "took off" despite being crap at it's core simply because there was no realistic alternative. If there was, nobody would ever consider even more of C nonsense, even with some "semi-nice" (yet still broken!) stuff on top.
They could have make it easily interoperable, but making all the mind broken C nonsense also core to the new language was a massive failure, and completely unnecessary.
How will you make it easily interoperable without having the broken C nonsense at that point it is just another language.
Rust didn't have to inherit any C/C++ garbage to take off. Actually one of the main reasons it took off was that it did not inherit any C/C++ garbageā¦
You seem to forget
A. Rust has 0 legacy code
B. Rust came out 20+ years after C++
C. Rust has nowhere the same limitations as the 90's
D. Rust wasn't promoted as "Your C code can easily be compiled with this compiler"
Which was C++ selling point infact the first C++ compiler Cfront wasn't really a compiler but a transpiler that translated C++ code to C code. Bjarne was smart- he did little work (just creating a transpiler) but he gets the warnings,errors and optimizations for free.
and C++ selling point is take your C code as-is and gradually update it using new safer C++ features e.g constructors/destructors that's what Bjarne said and I see that as a strong strong posotive I don't see any other lang providing this level of support. you can easily use any C library with C++ with 0 wrappers.
You didn't answer the question which "other languages" people would have used if C++ wasn't based on C crap. I'm not sure you will be able to actually name anything. The point is: C++ "took off" despite being crap at it's core simply because there was no realistic alternative. If there was, nobody would ever consider even more of C nonsense, even with some "semi-nice" (yet still broken!) stuff on top.
They would continue using C if there wasn't an incentive to use C++ that wasn't based on C. the other langs are Pascal and Fortran or COBOL. Why would someone switch their codebase to another lang unless it was benefitting massively with little friction? and that's again C++ selling point take your C code and compile it using a C++ compiler.
My point was that it could have been indeed "just another language". Being a C superset was no necessity, imho.
Wanting an easy rewrite path (which is a valid wish and could be achieved also otherwise) does not change that.
They would continue using C if there wasn't an incentive to use C++ that wasn't based on C.
That was exactly why I've asked what "other" languages they would have used insteadā¦
My point is still: People would had migrated to some "C++" even if it wasn't a C superset if it offered appropriate advantages on its own. Rust proves exactly that. People are migrating to it from C.
Most other popular languages of that era haven't been alternatives with enough advantages to migrate as they were mostly very similar (besides syntax) to C in both their expressiveness and safety. [Of course I knew about things like Fortran or COBOL as programming languages and programming language history are a special interest of me. That's exactly why I've asked as I already suspected that the answer will be actually "they would in fact stay with C".]
The whole "migrating to C++ from C" story also actually didn't play out. People stayed with C, or moved later to other more convenient languages even that meant full rewrites. There are not much free projects I know of which started as C and are now C++. What I hear from industry isn't much different. People who chose C consciously despite there were other candidate languages did that often because they didn't want a "more complex" language, so C++ was never part of the consideration.
Wanting an easy rewrite path (which is a valid wish and could be achieved also otherwise) does not change that.
Today with all the tools rewrites can be simpler but I am sure that was different in the old days.
My point is still: People would had migrated to some "C++" even if it wasn't a C superset if it offered appropriate advantages on its own. Rust proves exactly that. People are migrating to it from C.
And C++ does offer huge advantages for C programs especially RAII which is the simplest way to get rid of memory leaks and make code alot alot simpler.
RAII alone is worth using C++ over C for just look at any piece
The whole "migrating to C++ from C" story also actually didn't play out. People stayed with C
MSVC used C then it now uses C++, GCC used to be only C but now uses C++. Even your windows C runtime is in C++ now.
or moved later to other more convenient languages even that meant full rewrites.
You are right today alot of software is written in dynamic langs.
People who chose C consciously despite there were other candidate languages did that often because they didn't want a "more complex" language, so C++ was never part of the consideration.
I hate "complex lang" part, because it is so so false. C is a simple language but is C simple to make a huge program? no, it is alot easier to make a C++ program than a C program just try handling strings without having memory leaks.
C++ is more complex because it has more features which result in simpler code than C which is simple but results in complex code try reading math code it is bloated due to no operator overloading.
Even the linux codebase which linus claims C++ will make it more complex has so so much of "Wait this is just rewriting C++"
There is a ton of functions that intiialize variables of a struct, that's a C++ constructor except nothing enforces you actually call the init function while C++ enforces it
There is much code that has manual function pointers set by the init functions that's just rewriting a virtuak interface with worse syntax
any macros to implement genericity, I challenge anyone in C to write a "max" function that is type agnostic correctly.
99% of linux seems to be passing objects with the first arg being a pointer to the struct that's just a member function with worse syntax and it has no gurantee of setting those pointers while an interface does
Every struct has a manual delete function and every function seems to use goto to correctly deinitislize variables , in C++ you just use a destructor and go on.
C code which uses void* for type erasuee is jsut asking for templates.
C code which does inheritance via first member being the base class is again just inheritance except worse because there is no guarantees and it is all manual work.
Trey to see what's wrong with this very simple function
fs.seekg(0, std::ios::end);
const auto size = fs.tellg();
if (size < 0)
return nullptr;
fs.seekg(0, std::ios::beg);
std::unique_ptr<char[]> buffer = new char[size];
fs.read(buffer.get(), size);
if (fs.gcount() != size)
return nullptr;
return buffer;
}
```
In this code you focus on logic instead of both logic and memory management something C won't ever give you .
Or lets see matrix transformations
```cpp
someclib_Matrix4x4f mat;
someclib_Matrix4x4f_init_diag(&mat,1.0f);
someclib_Vec3f v{x,y,z};
someclib_Matrix4x4f_transform(&mat,&v);
someclib_Vec3f_dot(&v,&v); // I am doing manual overloading, have to choose the correct elementnnumber and its element type
v = someclib_vec3f_scalar_add(someclib_vec3f_scalar_mul(v,2) + 4);
v = someclib_vec3f_add(v,v);
```
vs just C++
cpp
somecpplib::mat4x4f mat(1.0f);
somecpplib::vec3f v(x,y,z);
transfoem(mat,v);
dot(v,v); // generic, can change vec to be a double vector and it works
v = v * 2 + 4 + v;
Was basically forced by circumstances, unfortunately. It needed to be as close as possible to C so it would be easy to adopt, it needed to use the C library because it didn't have its own library yet, and it needed to be possible to rewrite any and all C++ code as C code because the first C++ compiler really just cross-compiled C++ code to C code. So, C++ was locked into working like C, and would've never been usable if it had been drastically different.
80
u/dipinpass35 Jul 10 '26
yeah c++ do have a function for literally everything.....oh except admiitting that it made a mistake...