Pages: 1 [2]   Go Down
Author Topic: C++ in embedded  (Read 2873 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 32
Posts: 828
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

your efforts to learn OO and Arduino at the same time will lead to endless frustration.

Actually, this raises another important practical issue for C vs C++ that crops up a lot here in these forums: Because C++ is such a large, and sometimes quite unwieldy language, the beginner can easily become completely overwhelmed and lost, not seeing the woods for the trees.

C, being a small and compact language, is much quicker to learn, and I would recommend anyone not familiar with either language to start by reading K&R, and only after a bit of success with plain old C, to move onto to the relatively vast terrains of C++.

And thanks for your vote! :-)
« Last Edit: September 17, 2012, 01:28:28 pm by pico » Logged

WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
A well-written and structured pure C program for an embedded project will probably be just as maintainable and manageable as its well-written C++ counterpart.
I'm currently writing/porting an Arduino-style API to LPCs, because in LPC XPresso land the C compiler is free but the C++ compiler costs $256 I'm doing it entirely in C.

I think it's practical to write good OO-style code in C and I think that's what I'm doing, I would love some of the C++ features but that can't be helped in this case smiley-sad

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Full Member
***
Karma: 2
Posts: 158
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pico , very well done inclusive answer .

Many thanks
I will stick to C , bare C for embedded .

Elico
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5358
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I am not wrong the C++ is barely used in embedded
 programming , C is the facto language.

So I want to ask : what is the real advantage of C++ classes
 which is the main difference to C ?

'C' is only used by diehards. There's no advantage to using a C compiler instead of a C++ compiler unless the C++ compiler for your platform is rubbish (which barely happens these days as they all use GCC).

From the language point of view, objects can usually organize your work much better.

Example: Imagine you have 5 RGB LEDs connected, each with its own color and pin mapping. Each of those is clearly an object and will map nicely to a C++ struct.

You can program it in C with structs but every function to manipulate them will need a pointer to the LED's struct. Guess what? This is exactly what C++ is doing anyway, but neater.

Embedded programming is probably going to use an intermediate level between C and C++. It isn't going to use the full facilities of C++ (like STL, namespaces, RAII, etc.). You'll probably have more global variables than a purist would like, etc. That's fair enough because the programs being written are small.

If you restrict yourself to pure C then you lose that ability to choose a level. Things like LED objects are C++ but they make perfect sense. Why wouldn't you allow yourself to use them?


Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Why wouldn't you allow yourself to use them?

We all do, but we have more than enough water under the bridge to decide when its a good idea or not. Someone picking up and Arduino and a learn C++ book at the same time is in a very different situation though -

why does my program crash when i use new ?

is Arduino C++ the string class kills my program ?

etc etc etc

Duane B

Logged


Pages: 1 [2]   Go Up
Jump to: