LWN.net Logo

Why C?

Why C?

Posted Nov 12, 2004 15:44 UTC (Fri) by dps (subscriber, #5725)
In reply to: Why C? by ncm
Parent article: Sendmail X

It is claimed that

>It's easy to write code that is proof against buffer overruns in C++, with
>no cost to performance. Furthermore, the standard library probably has the
>data structures you need, implemented with much greater care than you >could afford to do yourself.

This is *completely* wrong in my experience. I can not write C++ code with the same efficiency as C code. In particular C++ std::string wastes cycles on copies or reference counts. In my expiernece C++ requires things like reference counts if you want to avoid nasty suprises (something goes out of scope somewhere and disappears prematurely).

You can get smaller and faster code by making sure every persistent object has an owner, who is responsible for freeing it or passing it on to someone else. This is not much more complex either, unless your design is broken.

I avoid the C++ algorithms and data structures because how they are implemented is too vague for my taste---I choose algorithms and data structures based on the data and how my program uses it. It is also The implementation really does matter, despite what the OO people claim.


(Log in to post comments)

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds