C or C++?

Jerry Feldman gaf at blu.org
Fri May 27 17:20:01 EDT 2005


On Friday 27 May 2005 4:46 pm, Paul Lussier wrote:
> Jerry Feldman <gaf at blu.org> writes:
> > As far as performance, C generally gives you better performance. but C
> > programmers tend to be skimpy with comments and tend to write tricky
> > code.
>
> That seems to be a "feature" of any given programmer.  Since Jim is
> going to be the programmer regardless of the language choice, the
> level of code cleverness and quality of commenting will likely be the
> same.
>
> FWIW, I'd go with C, just because there's at least some
> standardization for C and therefore, among compilers, whereas there
> isn't with C++, which would allow for somewhat better potability if
> that's important.
The opposite is true. C++ is more standardized than is C. 
GCC 3 series supports both the latest C++ 98 standard as well as the C99 C 
standard. C++ tends to be more portable accross platforms, and it also has 
a very rich set of standardized libraries.
For example, the string class is a very powerful class for the manipulation 
of strings where in C, there are a few basic string functions.
Given a case in C++ (i'm playing the syntax a bit loose):
string a("abc");
string b("def");
string c;
c = a + " " + c;
The result is "abc def"

In C
char a = "abc;
char b = "def';
char c[8];
one way:
sprintf(c, "%s %s", a,b);

or:
strcpy(c,a);
strcat(c, " ");
strcat(c, b);

In the case of C++, you have a class that overloads + as a concatenation 
operator. Additionally, the resultant variable c is expandable. In C, one 
must make sure that a sufficient sized array is allocated for the result. 

Another + for C++ is that most of the container classes in the STL have 
iterators that you can use to iterate through them, and standard search 
functions that are generic to the STL and operate on most of the STL 
classes. 


However, one of the benefits of C over C++ is generally lower overhead. For 
instance, every C++ class (and struct) has a constructor and a destructor. 


BTW: As I mentioned before, I am primarily a C guy, but I also think that 
Object Oriented programming has some very definite benefits and its 
drawbacks.


-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9



More information about the gnhlug-discuss mailing list