Pages: [1]   Go Down
Author Topic: What is the difference between C and C++  (Read 632 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which is better to use?
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What is the difference between C and C++

class, virtual, const, public, protected, private, template, friend, overloading, and name mangling.

Quote
Which is better to use?

In the context of programming your Arduino your question is irrelevant.  Your sketch is always fed to the C++ compiler.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So really just the structuring and keywords are the only distinction; therefore, there is no difference between the two.
Does one work better than the other with certain types of hardware?
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So really just the structuring and keywords are the only distinction;

That's not what was said.
Logged

Offline Offline
Edison Member
*
Karma: 28
Posts: 2045
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does one work better than the other with certain types of hardware?

The hardware doesn't care,  because it operates on some kind of machine language and it doesn't
matter what programming language that is compiled and linked from.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
class, virtual, const, public, protected, private, template, friend, overloading, and name mangling.
What does all this mean?
Logged

Offline Offline
Edison Member
*
Karma: 28
Posts: 2045
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well,  I could sit here and type out the lecture notes for three or four semesters of teaching programming,
or, on the other hand,  perhaps not.
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
class, virtual, const, public, protected, private, template, friend, overloading, and name mangling.
What does all this mean?

It means Google has a lot to say about this.
Logged

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you Google "C vs C++" you get almost 18M hits.... there's no shortage of discussion on the subject!
Logged

Retired from Arduino.
PMs are set to ignore all.

Offline Offline
Sr. Member
****
Karma: 9
Posts: 296
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

JFGI
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does one work better than the other with certain types of hardware?

Sort of.  Some processors have excellent support for virtual method tables while other processors do not.  Typically, virtual method tables are not used in C but they can be.

Quote
class, virtual, const, public, protected, private, template, friend, overloading, and name mangling.
What does all this mean?

Most of the items are keywords present in C++ but not in C.  The last two are concepts present in C++ but not in C.

Essentially, using the words in the list as keywords in Google searches will help you answer your question.
« Last Edit: March 04, 2013, 12:56:04 am by Coding Badly » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So really just the structuring and keywords are the only distinction; therefore, there is no difference between the two.

That is hardly "no difference". C++ has classes, for one thing. And templates.

Does one work better than the other with certain types of hardware?

The g++ compiler generates good code in either case.

I recommend you use Google a bit, this is a pretty general question.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6374
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
really just the structuring and keywords are the only distinction
well, you could say THAT about the difference between Cobol and C...

C++ is a different programming language than C.  Unlike most "new" languages, it was designed to be a sort of add-on to the C language.  So (almost) any legal C language program is also a legal C++ program.
C++ add a bunch of features, many of which are not used much in the arduino environment.  People have mentioned a couple of these, and they're complex enough that they're not easy to explain.

A C++ feature that shows up a lot, even in arduino code, is "polymorphism."  This encompasses the idea of being able to define function whose "definition" can be different depending on the type of the arguments.  So "print((int) 1);" and "print((char) 1);" call different code.

Some of the C++ features require resources and run-time libraries that don't exist for small microcontrollers like the AVR.  Many of the advantages of C++ are going to be less apparent in small programs.  My observation is that a lot of the purpose of "object oriented programming languages" like C++ stems from their ability to concisely define in libraries/classes many modern application concepts ("objects") like Windows and Mouse Buttons and so on.  If you've ever looked into writing or using a GUI library in an older language, you run into the problems solved by C++ pretty quickly.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which is better to use?

What is better, a dog or a cat?

Which is better, a pick-up truck, or a sports car?

A violin, or a piano?
Logged

Pages: [1]   Go Up
Jump to: