Re: C++ has Boost libraries, C?



Ian Collins wrote:
jacob navia wrote:

Mark McIntyre a écrit :


For reference, what you've done here is create an object. A simple
one, but still an object.

Of course. But there are no classes, no inheritance, no complications.
This is an object in the C sense: transparent, without any added
constructors, destructors, whatever.

I think C must remain at this level. By introducing operator overloading
(something Fortran 90 supports also for instance) the language remains
simple as it is now, albeit with more expressivity (I hope this is
the right word )


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.



.



Relevant Pages

  • Re: C++ has Boost libraries, C?
    ... But there are no classes, no inheritance, no complications. ... constructors, destructors, whatever. ... so you advocate extending the language with something that ...
    (comp.lang.c)
  • Re: Portability
    ... In this sense I mean that constructors and destructors are the ... wrong solution because they overly complexify the language ... programming idioms that are impossible to code in C. ...
    (comp.lang.c)
  • Re: weeding out c++ keywords from sys/sys
    ... code for constructors and destructors. ... The compiler keeps track where exactly the life ranges of objects begin ... On the other, other hand, Eiffel is a language with all ...
    (freebsd-current)
  • Re: writing drivers using C++
    ... destructors and default constructors as parts of the ... thing residing at some adressable memory location, ... explanation why I consider the existence of default constructors, ... You are talking about constructors not allocating memory. ...
    (comp.os.linux.development.system)
  • Re: advantages of C
    ... And constructors and destructors and templates and exceptions and ...
    (comp.programming)