C or C++

Does the arduino environment accept C only, or can you use C++? I am interested in learning a little more about programming for the arduino, but dont want to spin my wheels in the wrong direction.

You can use C++. In fact, a couple of the libraries around use object-oriented programming: Wire for one, and some of the LCD libraries. The hardware Serial interface also has its library written in C++.

I think all the Arduino supplied libraries are written in C++ and any sketch using these libraries is using C++ constructs.

If you are more interested in interacting with digital and analog i/o, then the C language with the Arduino abstractions can get you pretty far. But if you are seeking to implement larger or more complex problems, or just want to learn to use the rich expressive power of the C++ language in order to become a proficient programmer, then time learning C++ would be an interesting and worthwhile journey.

I think a good approach is to concentrate on the core C functionality to get your early sketches going while reading and absorbing the underlying concepts of C++. But feel free to jump in the deep end if you so desire.

Anyway, have fun!

I see several books entitled c programing for microcontrollers or embedded systems and the like, none of which cover the Arduino platform. Then I see bools like C Primer Plus or C++ Primer Plus, which get great ratings and are quite thick might I add. I guess my question is would getting a straight c/c++ programing book be overkill, taking me in directions not relevant to microcontrollers, or should I be waiting for a book entitled C Programing for Microcontrollers with the Arduino?

I don’t want to spent $50 to $100 on a book that won’t do the job.


P.S. I think I speak for several newbs like myself when I say why has no one written that last book i mentioned? :wink:

I think a lot of the C++ books you see will spend a lot of time explaining the many classes that are used when creating typical windows GUI applications, rather than the language itself. A book on C for microcontrollers is probably more useful.

Also, note that Arduino (and the underlying avr-g++ compiler) doesn’t support all of C++, so a lot of stuff that you read about in a C++ book won’t work. Details here: Frequently Asked Questions