Coming from Python, the whole C/C++ thing is kind of alien to begin with... and then 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? My admittedly crude understanding of the difference between the two is that C++ is (roughly) C with classes/objects. How does that affect which language or dialect (C or C++) should I concentrate on learning for use primarily with Arduino?
问题:
回答1:
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.
Hence do yourself a favor and learn C++. There are plenty of books and online resources available.
回答2:
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.
回答3:
Arduino doesn't run either C or C++. It runs machine code compiled from either C, C++ or any other language that has a compiler for the Arduino instruction set.
C being a subset of C++, if Arduino can "run" C++ then it can "run" C.
If you don't already know C nor C++, you should probably start with C, just to get used to the whole "pointer" thing. You'll lose all the object inheritance capabilities though.