A note on C, C++, and Arduino programming

I see a lot of questions on the Web about how Arduino code relates to C and/or C++.  In a nutshell,  Arduino code IS basically C/C++ code.  Arduino uses a set of standard libraries to hide some of the functionality behind the curtain, making things easier for the newcomer to get started in the hobby.  For example, rather than setting specific bits on a “Port” to identify a pin as an output, coding something like DDRC.1 = 1;   after looking up which “port register” and which bit in the register controls the pin you want, you simply can code something like:  pinMode(8, OUTPUT);

This can also save time and effort for more experienced developers as well.  Arduino is not just for newbies.  There are tradeoffs, however.  For example, using the Arduino library to set pin modes takes longer, in terms of CPU processing time, than setting them more directly.  BUT, because Arduino basically IS C, you can often (but not always) just drop in the direct code you need, and still use the Arduino libraries for the rest.  And if you someday want to go straight to AVR C programming, skipping the Arduino IDE’s and libraries entirely, there are ways of doing that to with your Arduino board.

You may have noticed that I said Arduino is basically C/C++.  Well, which is it?  Aren’t they two different, if related languages?  Yes, they are.   C++ is mostly a superset of C, adding object oriented programming concepts.  C++ started as “C with classes”   but C is no longer completely a proper subset of C++, as the two languages evolved a bit differently over time.  These days, languages usually have both the core language itself and a set of standard libraries.  These libraries have already coded frequently used routines in an efficient manner,  so you don’t have to keep reinventing the wheel.  As I understand it, Arduinos support C++ core language features and the common C libraries, such as math.h, but NOT the standard C++ libraries.  So while you can use objects and other core C++ language features, you can’t draw from the C++ library.  At least this is my understanding.  Please let me know if I’ve gotten something wrong.

3 thoughts on “A note on C, C++, and Arduino programming

  1. Pingback: | مدونة فابلوجيا

  2. Dear sirs,

    Could someone send me an example of “Hello World” code which could be directly uploaded to the Arduino board directly using AVRDUDE, and without the need to us the Arduino IDE?
    I don’t know which libraries to include in my code.
    Best regards

Leave a Reply

Your email address will not be published. Required fields are marked *

The maximum upload file size: 512 MB. You can upload: image, audio, video, document, spreadsheet, text. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop files here