Ian said:
Interesting, so you advocate extending the language with something that
boils down to syntactic sugar while dismissing the one feature
(constructors and destructors) that enables C++ to what C can't (RAII).
Look, C is just syntactic sugar for assembly, as all other
computer languages.
Why constructors/destructors are unnecessary?
--------------------------------------------
Because a constructor can be called, when needed, by the
programmer at the initiliazation of the object being created.
int fn(void)
{
SomeType s = CreateSomeType("Name",10.7);
// use some type
DestroySomeType(s);
}
This means that the incredible inefficiency of having a function call
for each object creation can be avoided if you wish. It means that
the complexity in the compiler that needs to figure out if the
constructor is a "trivial" one and can be optimized away can be avoided
too.
You will immediately cry:
"But the freeing of the object is very error prone"
"You will end with a memory leak"
Within lcc-win32 I have developed a better solution: a GARBAGE
COLLECTOR, that frees you from all the destructor/freeing memory
woes.
Of course that is NOT the only solution, since in an embedded system it
is better to manually create and destroy objects when memory is scarce.
No GC there, because it is an optional solution, not one that the
language FORCES you down your throat if you want it or not!
One of the worst features of C++ is precisely the constructors /
destructors stuff. Since there is no GC, you have to have exception
handling to destroy the objects that are out of scope when throwing
an exception. None of this is needed in the schema proposed in
lcc-win32: the GC takes care of that without any extra overhead.