70
votes

I see in one place that Arduino uses 'standard' C, and in another that it uses 'standard' C++, so on and so forth.

Which is it?

1

2 Answers 2

86
votes

Arduino sketches are written in C++.

Here is a typical construct you'll encounter:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
...
lcd.begin(16, 2);
lcd.print("Hello, World!");

That's C++, not C.

0
23
votes

Both are supported. To quote the Arduino homepage,

The core libraries are written in C and C++ and compiled using avr-gcc

Note that C++ is a superset of C (well, almost), and thus can often look very similar. I am not an expert, but I guess that most of what you will program for the Arduino in your first year on that platform will not need anything but plain C.

4
  • 4
    C is indeed almost a subset of C++. However, non-shitty C code will look very different from non-shitty C++ code.
    – user395760
    Aug 4, 2012 at 23:58
  • True, but non-shitty C code will compile as C++ (and C programs that are not C++ are shitty). Of course, good C++ code will not artificially and arbitrarily restrict itself to C.
    – tiwo
    Aug 5, 2012 at 0:03
  • 13
    Still nope. For instance, the return value of malloc shouldn't be casted in C, yet in C++ it's mandatory. Now, allowing C++ to link and interact with C code is great, but for that you mostly need to avoid some reserved words and add a conditional (preprocessor) extern "C" to the header. That's quite a difference though. Also, there's a whole bunch of lovely C99 and C11 features which C++ does not support; why would good C code artificially restrict itself to a subset of C++?
    – user395760
    Aug 5, 2012 at 0:10
  • 3
    @tiwo Non-shitty C code most definitely not compiles with a C++ compiler. For example, whenever you use variable length arrays it won't compile. Or whenever you use structure literals.
    – fuz
    Nov 15, 2016 at 12:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.