View Full Version: C/C++ Libraries

C++ Learning Community > C++ in General > C/C++ Libraries


Title: C/C++ Libraries
Description: ...


Jim - February 8, 2004 08:19 PM (GMT)
Me and my freind got into this 'discussion' and he seems to think that C libraries are better than most C++ libraries. he was also discussing that C is better than C++ in every way imaginable. first of all, i am new to C++ and i like to argue about things of which i know nothing. my main argument was "Why did they make C++ if C is better and faster and has better libraries?!". i feel i should know more about the subject before i take his opinion and chew its head off. :D so what i'm trying to say is, Why is C++ better, and what did he mean by C Libraries?

adam_paige - February 9, 2004 01:09 PM (GMT)
I don't know your friend but from what you have said, I have an idea of the type of person he is. Statements like "C is better than C++ in every way imaginable" tell me that this person probably doesn't know what he is talking about and is probably unwilling to learn. Let me warn you, if I am right, that he may not accept your arguments. A topic like this takes more than just a little knowledge to validly defend. I question, although I could be wrong, whether someone making statements like that, with no argument, are adept enough to do so. If his argument was that C has better libraries, which isn't true, then you should tell him that C libraries are also part of C++.

At Bjarne Stroustrup's website, the creator of C++, I found these points that you may want to look at. They are all on the same page if you want to go to the first one and look around.

http://www.research.att.com/~bs/bs_faq.html#C-is-better
http://www.research.att.com/~bs/bs_faq.html#C-is-subset
http://www.research.att.com/~bs/bs_faq.html#difference
http://www.research.att.com/~bs/bs_faq.html#merge
http://www.research.att.com/~bs/bs_faq.html#really-say-that

This is a topic that I believe has been exhaustively covered, if you want to do a search. The links I provided are going to be biased for obvious reasons.

For what it's worth, some very adept people would take the stance that your friend has, they would just defend it well. Personally, I started with C and greatly prefer C++.

myork - February 9, 2004 04:25 PM (GMT)

The real answer is 'C' is good for some problems.
While 'C++' is good for other problems.

The language you choose to implement the solution to your problem depends on the problem you want to solve.

dr voodoo - February 9, 2004 04:51 PM (GMT)
A solid argument in my eyes are templates. In C++ you can do with very few keystrokes (normally 5-15 letters) what in C you have to do with copy/paste, scolling in the code and a find/replace. Compare the amount of code of a C like map implementation with the C++ map template.

Another good argument (although not many people that don't know it will understand it) is the string class that can nearly be used just as build-in type.

A weak argument is that const int have a scope and therfor have an advantage over #define.

The problem with convinced C programmers is that they are against OOP and all other features of C++ go in that direction, therefor they are unlikly to accept those arguments.

But templates are also useful in procdural programming. Ex:
CODE
#include<stdio.h>
template<typename T,int num>
int fwrite2(FILE*file,T t[num])
{
     return fwrite(t,sizeof(T),num,file);
}
template<typename T>
int fwrite2(FILE*file,T&t)
{
     return fwrite(&t,sizeof(T),1,file);
}
int main()
{
   FILE*file=fopen( /*...*/ );
   int a[5];
   fwrite2(file,a);//writes the whole array
   fwrite2(file,a[0]);//writes 1 element
}

And the whole thing without any runtime overheat.




* Hosted for free by InvisionFree