operator+(int a, int b) __gcc_internal_int_sum(a, b)
This way, we can change (through overriding) the way these operations work (rounding, overflow, coercing, etc.), without having to define non-idiomatic functions to do so. A lot of undefined behavior can be made user-defined this way.
d + A*B*(c*(a*b))
Not this: vector_add(mv_multiply(matrix_multiply(A,B),vector_dot(a,b)*c),d)IMHO vector math is about the only place where operator overloading is acceptable in C++.
((A `mmul` B) `mvmul` (a `vdot` b) * c) `vadd` d
Still not as nice as operators, but not terrible either. mpz_mul(res,x,y);
mpz_mul(res,res,z);
vs
x*y*z;
``` v3 r = Add_v3(v, w);
v4 w = Scale_v3(r, 1.0);
You can definitely write a little 3D graphics backend this way.C's lack of operator overloading can be annoying for some tasks, however I still like to use C for almost everything to this day, because of the lightness of going through old code and seeing instantly what happens - never have to run any type resolution in my head.
And importantly, _knowing_ that I don't have to do this. Because I might almost never have to do this in cleanly written C++ code, but how do I know?
Function overloading can be done compile time, eg., parametrically:
add(3.0, 1.0) -> compile to add_float32_float32
add(1, 2) -> compile to add_int32_int32I guess we'd need C to have a special syntax to compile in something like a vtable
add_f32_f32(x, y) calls add(MAGIC_NO, x, y)
and add has a big switch on MAGIC_NO for selecting implementation...
You'd need a keyword for this, "multi int add(int a, int b) ..."