You are here

C vs C++

12 posts / 0 new
Last post
gluxon
gluxon's picture
Offline
Last seen: 3 years 7 months ago
Developer
Joined: 2008-06-21 19:26
C vs C++

What are the disadvanteges and advanteges of C and C++?

Okay... I've swear this must have been mentioned before but I can't find anything like this through google or other sites.

I asked this question on the IRC a while ago but I didn't get much luch upset for "C++ has more commands and is more widely used." or something like that. I've also heard that C is more cross-platform than C++

But I need to know which one suits me better. And when you speak/post, please don't mention which one is easier to learn. I don't care about that right now.

So here are some pretty basic questions...

  1. What can C do that C++ can't do? (Features, Advanteges, etc)
  2. What can C++ do that C can't do? (Features, Advanteges, etc)
  3. What Operating Systems do C support?
  4. What Operating Systems do C++ support?

Thanks.

P.S. Wow... I typed all this on my DSi... sad, eh?.

m2
Offline
Last seen: 13 years 2 months ago
Joined: 2006-12-12 12:00
Both can do exactly the

Both can do exactly the same.

There are only 2 advantages of C:
-Is slightly more popular. In practice, this applies only to embedded devices like dishwashers or GPSes, because for all regular PCs (and their OSes) you can get compilers for both languages.
-Generates slightly better machine code...but usually at the expense of (much) worse program code

C++ is almost a superset of C, many C programs are correct C++ ones, just change file extensions. And C++ offers many useful mechanisms that make it's code better, more readable, easier to manage, more bug proof etc.
The biggest advantage of C++ is it's flexibility: you can write code at rather high level of abstraction, but in places where you need extra performance, you can get very low, as low as portable (code-portable, not pendrive-portable) language can go.

Therefore C++ is highly recommended.

I learned C first myself because I thought that better code is worth it. It's not. Really.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

gluxon
gluxon's picture
Offline
Last seen: 3 years 7 months ago
Developer
Joined: 2008-06-21 19:26
Thanks. Now I know I'm going

Thanks.

Now I know I'm going to go for C++. I've already found two sites that'll help me learn the programming language.

http://www.cprogramming.com/
http://www.learncpp.com/

Now I just need a compiler(s) that turn the written script into executable files readable for Linux, Windows, and Mac. And of course, they have to be free.

m2
Offline
Last seen: 13 years 2 months ago
Joined: 2006-12-12 12:00
http://www.mindview.net/Books

http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

GCC should be available for all these platforms.

And C++ is a programming, not a scripting language. Smile

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

gluxon
gluxon's picture
Offline
Last seen: 3 years 7 months ago
Developer
Joined: 2008-06-21 19:26
Hey!I remember checking out

Hey!

I remember checking out a book called "Thinking in Java" Blum

BTW, I think you're talking about g++ not gcc.

Zach Thibeau
Zach Thibeau's picture
Offline
Last seen: 1 year 6 months ago
Developer
Joined: 2006-05-26 12:08
g++ is a subprogram for gcc

g++ is a subprogram for gcc (gcc being the frontend) so m2 is correct for using gcc in his sentence

your friendly neighbourhood moderator Zach Thibeau

m2
Offline
Last seen: 13 years 2 months ago
Joined: 2006-12-12 12:00
I think that GCC has 2

I think that GCC has 2 meanings, GNU C Compiler and GNU Compiler Collection. The latter for sure.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

gluxon
gluxon's picture
Offline
Last seen: 3 years 7 months ago
Developer
Joined: 2008-06-21 19:26
Ha!

This time I know you're wrong!!! GCC stands for gluxon.co.cc. LOL!!!

Okay here's you're history lesson (that I learned today from google). GCC used to stand for GNU C Compiler, but then switched to GNU Compiler Collection when g++ joined the group Smile

P.S. Curse GNU for stealing the gcc acronym. (But GNU is so awesome I'm willing to let it go Smile)

qwertymodo
qwertymodo's picture
Offline
Last seen: 11 years 9 months ago
Joined: 2008-03-17 19:08
Depends on what you want to do

Ok, so the idea that C++ follows it's name and is C plus plus more and more and better than C is kind of right in most circumstances. C++ does have more functionality than C, but at the expense of efficiency. It is what's considered a "higher-level" language than C. This basically means that C++ source code is more human-readable whereas C is more "computer readable", so C usually results in more efficient programs, at the expense of more complex code. C++ also implements what is known as "object-oriented" programming, which is a really nice thing in and of itself. However, having done both, C first, my first semester of C++ was all like "hey I can do all of this in C but this is nicer". So for starting out, I would suggest C++, but as was mentioned about GPSes and such, C is much more useful for more restricted systems such as those, so it does have its uses, although at this point they are mostly either very specialized or for people who are very familiar with it and still prefer to do things that way. The same can be said of other lower-level languages such as assembly, although this is a more extreme example. However, for the new user, I would suggest C++. You can do everything that you can in C, usually with more user-friendly syntax, and if you delve into the object-oriented part it allows for very useful functionality as well.

Quamquam omniam nescio, nec nihil scio.

m2
Offline
Last seen: 13 years 2 months ago
Joined: 2006-12-12 12:00
I would suggest not to go to

I would suggest not to go to C at all, but rather learn C++ well.
Nobody serious writes in C nowadays unless platform doesn't support it.
Even though compilers for C generate a bit better code (I always wondered why is it so...), the difference is very slight and C++ has huge advantages also in the performance field like better libraries or partial evaluation via templates.

In C++ you can write critical parts as low as in C and smoothly move higher or much higher when it's viable.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

batateam
Offline
Last seen: 14 years 11 months ago
Joined: 2009-05-16 02:10
C++ does have more

C++ does have more functionality than C, but at the expense of efficiency. It is what's considered a "higher-level" language than C. This basically means that C++ source code is more human-readable whereas C is more "computer readable", so C usually results in more efficient programs, at the expense of more complex code. C++ also implements what is known as "object-oriented" programming, which is a really nice thing in and of itself. However, having done both, C first, my first semester of C++ was all like "hey I can do all of this in C but this is nicer". So for starting out, I would suggest C++, but as was mentioned about GPSes and such, C is much more useful for more restricted systems such as those, so it does have its uses, although at this point they are mostly either very specialized or for people who are very familiar with it and still prefer to do things that way. The same can be said of other lower-level languages such as assembly, although this is a more extreme example. However, for the new user, I would suggest C++.

[Mod SL, I removed all of the spam links in this post as there is actually some good content here, I just removed your other post, the content wasn't worth saving, please stop adding inappropriate links to your posts]

m2
Offline
Last seen: 13 years 2 months ago
Joined: 2006-12-12 12:00
I'll repeat myself: In C++

I'll repeat myself:
In C++ you can write critical parts as low as in C and smoothly move higher or much higher when it's viable.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

Log in or register to post comments