Re: weeding out c++ keywords from sys/sys

From: Andriy Gapon <avg_at_icyb.net.ua>
Date: Mon, 16 Feb 2009 10:57:12 +0200
on 16/02/2009 07:56 Andrew Reilly said the following:
> The problem with C++ isn't really the functions that it
> provides, it's the functions that it doesn't.  Personally, I'd
> like C++ a *lot* better if it required a garbage collecting
> runtime.  The problem with the way it works at the moment is
> that object creation interacts with argument promotion and
> constructors (and C++'s ability to grab references inside the
> guts of objects, whch it inherited from C) in such a way that
> you can have temporary object creation inserted by the compiler
> in the middle of an expression, with no way to ensure that
> the resulting object is reaped at the right time.  And that's
> because the compiler can't, in general, know what is the right
> thing to do: if the called function retains the reference in a
> long-lived structure then the temporary should be constructed
> on the heap, and explicitly freed somewhere else.  If it isn't
> retained, then the temporary object should be collected as
> the expression scope is exited.  Since there's no way for the
> compiler to make that call, you almost inevitably wind up with
> either memory leaks or you constrain yourself to operate with a
> restricted, not-quite-object-oriented style, which can't really
> be enforced by the compiler.  I don't need to mention what a bad
> idea memory leaks are in kernel mode, right?

This is the first time in my life that I hear about temporary objects on 
the heap and/or memory leaks through temporary objects. Either you are 
remembering a bug in some ancient C++ compiler or you are referring to 
some buggy code.

As to the conversions through constructors, conversion operators and 
implicit type promotions - I personally had much less incidents because 
of that than I had incidents in C with passing/casting something 
incorrect via void*. This is to say that C++ is far from perfect and 
there are languages that are much better than it, but C is even (much) 
less perfect.
And of all languages out there, I think, that C++ comes closest to a 
definition of "enriched", "better", "fortified" C. Which implies much 
lower entry barrier (and possibility for limited/gradual introduction).

-- 
Andriy Gapon
Received on Mon Feb 16 2009 - 07:57:26 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:42 UTC