[SOLVED] Arduino language

EDIT: To anyone coming here from a search engine, etc, I've now summarized everything I learned in this and a few related threads in the article "35-second Arduino language reference for expert programmers".

The below is just preserved for historical reasons.

--

[original title was "Nomenclature: is Arduino a language?". Original post:]

I am reviewing edits I might make to an article I wrote, based on feedback I received in our thread here. Someone suggested:

"There is no Arduino language! This is part of why some people hate Arduino, because they never took the time to actually understand what Arduino is and is not. If there really was an Arduino language that would be a good reason to hate it but instead we're using real, professional, programming languages. Sure, the IDE takes care of a bit of the less beginner friendly stuff but you can override any of that if you want."

I've reviewed (meaning read through) the linked post, "Embed with Elliot: there is no Arduino 'language'."

To give you my qualifications for talking about programming languages: in purely chronological terms, i.e. if you measure the time that I first wrote a single line of any programming language, I've been programming since I was a young teenager. This extends from basic scripting languages to compiled languages to things running on a browser.

The author of the "Embed with Elliot" piece writes:

There is no “Arduino language” and your “.ino” files are three lines away from being standard C++

In my opinion, something can be called a language even if even three lines are not involved. For example, on Windows you can rename a .docx word file to .zip, and open it with an archive program. You can see images in there and other assets. Does this mean that there is no such thing as a Word document, since inside it is actually a zip file? Surely not.

Three lines is quite a transition. It means that someone who has spent a whole year writing Arduino code cannot write a C++ program without looking up the C++ language. Since they have been writing in Arduino. How should they figure out "#include" lines? By definition then it's not the same language: only almost the same language. The Arduino language is very close to C/C++. I don't see the mistake in calling it a language. Further .ino files are not the same as .c[pp] files.

So, I would say that it is fair to say "the Arduino language is almost exactly the same as/very close to C/C++".

Therefore, I would like to reject the edit suggestion to remove the phrasing that Arduino "is a language". In my article I want to continue to use this phrasing. Would I be technically correct? (In light of my arguments above.) Bear in mind that Arduino has a language reference page. After reading it, you can begin to write in the Arduino language, without having to look up references that don't refer to that.

If in light of what I've written above, you judge that I am still confused, I would like your additional information. I do find the Elliot post to be interesting, and I would say it means that those who happen to know C or C++ can easily add it to Arduino projects, since the Arduino IDE can use them easily. Is this a fair way to rephrase the Elliot post?

Thanks for your information about these exact differences and your advice regarding my edit choice.

No, no, no.

Arduino is not a language. Here's why: Your .ino file is not what is uploaded to the board. The .ino file is converted to C++ via the compiler and sends the C++ code to the board. In a sense, the IDE serves similar to an autocoder, taking a more primitive version of the code and converts it to what the C++ code should be.

Arduino is not a language, its just that the IDE is more of an autocode generator.

P.S. I wish I started coding as young as you, sir :slight_smile: !

Power_Broker:
The .ino file is converted to C++ via the compiler and sends the C++ code to the board. In a sense, the IDE serves similar to an autocoder, taking a more primitive version of the code and converts it to what the C++ code should be.

No, C++ code is not sent to the board at all. Machine code is uploaded to the chip.
This will clarify:-
Build Process

No, it's simply a brand name for a development system made up of hardware and a compiler. I believe the user language is a subset of C++, not that it matters, as the IDE sends machine code to the chip.

Arduino is not a language, but when people speak of the "Arduino language', I believe they mean C++ with Arduino specific extensions loaded from the arduino.h library.

This thread is not really helping. :smiley: :smiley: :smiley:

Let me ask this way. (A) If I write .ino with vim, can I then rename it to .cpp, send it to gcc, and upload the results?

In what way will this differ from (B) pasting the same thing I wrote into vim, into the Arduino IDE and uploading it that way?

I assume under the first hypothetical (A), gcc does the compilation; under the second hypothetical (B), the Arduino IDE has a built-in compiler.

Is all this correct? Does this comparison break down anywhere? (Specifically in sending an .ino file to gcc)?

Are .ino files ANSI standard C89? If not, what standard do they follow? Does Arduino know any C++ or only just C?

Finally, can you use the arduino IDE from the commandline like gcc? Any other differences?

Please tell me the comparison of (A) and (B) and the results. Thanks so much.

curious48,
My view is that "Arduino" is definitely not a language. Not anywhere close.

The Arduino IDE provides a development/build environment and defines and provides a runtime operating environment that can be extended further using C++ code, but it sure isn't a language. The actual language being used is C++

I believe that things in Aduino-world are confusing because the founders call everything "Arduino".
The board, the IDE, the tools, the libraries, and even claim to use a language called "Arduino".
This makes it very difficult to refer to the individual components/pieces.
At one point several years ago, after one of them said that Arduino was actually more of a lifestyle, I responded with something like:

"I have an Arduino that I program in Arduino using Arduino" just to demonstrate the ludicrousness of it all.

But in terms of "Arduino" being an actual language, it seems like a pretty weak argument since the code (and sketches) are all using C++. All the IDE does is massage the users "sketch" into being valid C++ if it isn't already and then compile it.
That doesn't qualify it as a language since the "Arduino language" is not defining any grammar or syntax which is what any real language must do.

The IDE does comes with some code to provide some functionality for the supported boards as well some "libraries". While the IDE calls things "Arduino libraries" they are not really libraries but simply a collection of code that kind of sort of act like libraries in "normal" development systems.
The only code in the Arduino IDE system that is a real library is the core code. That code is compiled and archived into a real library and linked against at link time.

I forgot to say earlier, but I'm with the others. "Arduino" is most definitely not a language. The language is C++.
Dig into any Arduino function that you might call a part of the "Arduino" language, and the source files are C or C++.
"Arduino" is a just a brand name, a registered trademark. There's an Arduino IDE, Arduino boards, Arduino accessories but no Arduino language.

Arduino is not a language. It is a hardware platform and a programming environment. The language is simply C++. The main thing that the arduino gestalt has is a Hardware Abstraction Layer. That is, you can write digitalRead(3) without having to worry about the details of where the ports are memory-mapped to. If anything, that's the core of what makes it useful. But that would be nothing without hardware that's rugged enough to manage being handled and poked at by hobbyists. Let's also not forget the importance of shields and modules.

So:

  • rugged(ish) hobbyist hardware
  • open source makes it possible to make and sell 3rd-party plugins
  • hardware abstraction layer - an API
  • IDE that makes it easy to upload the machine code (a lot happens in the background)
  • the community

But it certainly isn't "a language". Perl is a language. Lisp is a language. The IDE uses C++, but it could use anything else that could be compiled down to run on the AVR.

Let me ask this way. (A) If I write .ino with vim, can I then rename it to .cpp, send it to gcc, and upload the results?

Yes. This is exactly what ordinarily happens when you git the 'go' button in the IDE. The code is sent to gcc, then it is linked with a runtime library same as any other C program - most notably it is linked with libc which is the standard C library that pretty much every C program uses. Then it is uploaded over the USB.

You could do all this with command-line tools if you wanted, and I think that that's how the IDE actually does do it: it issues java System.shell() commands.

If you replaced the arduino libraries with your own stuff implementing main() and the abstraction layer (digitalRead(), etc) - it would just be a regular C++ program.

curious48,
You seem to be confusing several different things and trying to lump several together operations, from a lack of understanding how programs are converted from source code into executable machine code.

There are many different tools involved in building and uploading an Arduino sketch and none of them are a "language".
The Arduino IDE is simply a GUI wrapper tool that runs many commandline tools under the hood.

Much of what is in the IDE is a re-inventing of the wheel for what is in the tool 'make' to control the build process.
None of the actual compiling, linking, or uploading is done by the IDE itself.
i.e. the IDE simply decides what needs to be done/built and runs the appropriate commandline tool to do what needs to be done.

And yes the newer IDE versions can be run directly from the command line as well rather than interacting with as an actual GUI program.

The IDE first acts as a pre-processor that runs before the other tools to massage the .ino into a .cpp file to be a valid C++ code and to also insert the arduino header to pull in the Arduino environment defines/macros and classes.
That is pretty much the only thing that IDE actually does itself. Everything else, is done by commandline tools since it all involves using C++.

But it is possible to write your sketch such that it is already valid C++ code and contains everything needed to use the Arduino compile and runtime environment.

What is being called a "Hardware Abstraction Layer", is really a runtime environment, provided by the Arduino core code. But that environment is simply a collection of C & C++ code that provides a consistent API across multiple hardware platforms.

After the IDE pre-processes your .ino file to create the .cpp C++ file, it then runs a series of command line tools to compile the sketch (which is now valid C++) as well as all the other needed sources and link them together to create the .elf object file. It then runs additional command line tools to convert that to a .hex file and eventually runs an upload tool like avrdude to do the actual upload.
Again, the IDE is not actually doing this but simply calling other command line tools to do the actual work.
This is all possible because the "Arduino language" is actually C++ and so the IDE can use standard C/C++ embedded tools to do the actual compile, link, and upload.

--- bill

"I have an Arduino that I program in Arduino using Arduino" seems fine to me?

I read this as:
"I have an Arduino-compatible board, that I program in the Arduino [redacted], using the Arduino IDE".

In the word "redacted" is what this thread is about - obviously some people disagree that this word should be "language".
Let me ask this. Many people in this thread are saying that the Arduino "language" is C++.
But in C++ this is how you change the size of an array:
[c++ changing the size of an array]c++ changing the size of an array](c++ changing the size of an array - Google Search)
There are two helpful answers:

n C++ you can do:
int *array; // declare a pointer of type int.
array = new int[someSize]; // dynamically allocate memory using new
and once you are done using the memory..de-allocate it using delete as:
delete[]array;

This is correct and insightful, but really, one should encourage the use of std::vector

and:
you want to use std::vector in most cases.

std::vector array;

array.resize(someSize);
But if you insist on using new, then you have do to a bit more work than you do in Java.

int *array;
array = new int[someSize];

// then, later when you're done with array

delete [] array;
No c++ runtimes come with garbage collection by default, so the delete[] is required to avoid leaking memory. You can get the best of both worlds using a smart pointer type, but really, just use std::vector.

So, this is C++. Will this work? Is this appropriate usage?
If we look at the Arduino language reference, under array it says:

Arrays in the C programming language, on which Arduino is based, can be complicated, but using simple arrays is relatively straightforward.
Creating (Declaring) an Array
All of the methods below are valid ways to create (declare) an array.

int myInts[6];
~~ int myPins[] = {2, 4, 8, 3, 6};~~
~~ int mySensVals[6] = {2, 4, -8, 3, 2};~~
~~ char message[6] = "hello";~~

So, at a minimum, this seems to mean that Arduino is only based on C, not C++.
Since this whole thread is kind of pedantic, it makes it really really weird that not one but two of the commentors wrote "C++" and the linked article also says "C++".
In what sense is Arduino possibly C++ as opposed to C?
People are writing "Arduino is not a language, but when people speak of the "Arduino language', I believe they mean C++ with Arduino specific extensions loaded from the arduino.h library." <---- this should read "I believe they mean C with Arduino specific extensions", right?
bperrybap writes:
>The Arduino IDE provides a development/build environment and defines and provides a runtime operating environment that can be extended further using C++ code, but it sure isn't a language. The actual language being used is C++
Do you mean C? "The actual language being used is C"? (Not "C++").
Oldsteve writes:
>"Arduino" is most definitely not a language. The language is C++.
Again, does he mean C?
Paulmurray writes:
>Arduino is not a language. It is a hardware platform and a programming environment. The language is simply C++.
Again, does he mean C?
It seems incredibly odd that every single commentor would make this mistake in this pedantic thread. Please explain why they are using the term C++ and not using the term C?
I am more confused than ever. Note: I've programmed in both C and C++. In general, C++ is a superset of C and you can use C constructs. But not the other way around - I've never heard anyone refer to C code as C++ code, unless they're being incredibly casual (like "C/C++"). In this sense, sure, Arduino is "like C++ code".
But now that we're being very technically precise, shouldn't all of the above references to C++ be renamed as references to C?

[EDIT: this was all mistaken. Arduino is not a "subset" of C++. It is the Project's name for C++, which for marketing reasons it does not use. The IDE also does some light translation before using a standard C++ compiler.]

curious48:
I am more confused than ever. Note: I've programmed in both C and C++.

Maybe think of it as a patois.

:wink:

curious48:
Oldsteve writes:

"Arduino" is most definitely not a language. The language is C++.

Again, does he mean C?

No. I meant what I wrote - C++.

C++ is backwards compatible.

There are errors in the documentation, but Arduino primarily uses C++, as we've all indicated.
Try this:-

void setup()
{
    Serial.begin(115200);
    int *pVal = new int[10];
    pVal[0] = 123;
    Serial.println(pVal[0]);
    delete[] pVal;
}

void loop() {}

'new' and 'delete' are only valid in C++, not in C. If Arduino used C, this would not compile.

You could also use 'malloc()' and 'free()', because of the backward compatibility, but in C the 'new' and 'delete' method of handling dynamic memory allocation would not work.

Disclaimer: I'm not in any way saying that dynamic memory allocation in embedded microcontrollers is a good thing, this is just an example. Easier than writing a 'class' example. :slight_smile:

But now that we're being very technically precise, shouldn't all of the above references to C++ be renamed as references to C?

Definitely not. As we've all stated, it's C++, not C.

At some point you need to stop arguing and accept facts. :slight_smile:

OldSteve:
Disclaimer: I'm not in any way saying that dynamic memory allocation in embedded microcontrollers is a good thing, this is just an example. Easier than writing a 'class' example. :slight_smile:
Definitely not. As we've all stated, it's C++, not C.

I didn't see as many examples like this. Most examples just use the Arduino language reference things. You just wrote that dynamic memory allocation isn't good in embedded microcontrollers. What about classes and objects generally?

I am now confused regarding why / to what extent, then, Arduino (patois + culture + habits and what is encouraged) is different from C++. Why not use C++ concepts such as classes extensively? There is little overhead, it's more about how you think about things.

curious48:
I didn't see as many examples like this. Most examples just use the Arduino language reference things. You just wrote that dynamic memory allocation isn't good in embedded microcontrollers. What about classes and objects generally?

Classes are fine, much of the Arduino code and libraries are written using classes.

Why not use C++ concepts such as classes extensively? There is little overhead, it's more about how you think about things.

See my line above. :slight_smile:

Take a bit of a look around in the source code. For instance, "Serial", which itself inherits from the "Stream" class:-

class HardwareSerial : public Stream
.
.
.
extern HardwareSerial Serial;

Edit: And "Print" is a class, with 'print()', 'println()' etc member functions, "Servo" is a class, "File" is a class, "Wire" is a class, ("TwoWire"), etc etc

I did a fairly lengthy explanation of what the IDE does to your sketch here.

The fact is, the .ino file is treated as C++, and is modified by the IDE pre-processor slightly to automatically generate function prototypes.

So, Arduino is not a language. You may as well argue that the output from the Visual C++ "wizards" are a new language. But they are not. The wizards just generate C++ for you.

@curious48 - you mention std::vector. That is a library (the Standard Template Library) which is written in C++. It is not, itself, part of C++. It is a library written in C++. Just like the works of Shakespeare are not a new language. They are written in English.

You can install implementations of the STL on the Arduino, and then you have std::vector (and std::map etc.). The same thing applies on "normal" C++ installations, except that they may have installed the STL for you, so you confuse the library with the language.

When programming, one has to distinguish between the "Language" and "everything else that goes into writing the program" - the "environment." That includes the libraries, the operating system (if any), the compilers, and the build environment. Some languages/systems will blur the distinctions - if you write a fortran program for an IBM370 system, it would be pretty significantly standardized fortran, and all or most of what makes it specific to a particular task would be handled by external setup (JCL in IBM-speak) that would map Fortran-style abstracted 'files' to actual disk images or card readers or printers or whatever. The original Pascal was similar.

The best analogy I can think of offhand is Mac vs Windows.
You can take a lovely C++ program (that everyone agrees was written in C++) from a Windows system, and when you try to move it to a Mac, it won't work. It won't even compile, and you probably need to do a lot of work before you can even attempt to compile it (What with "Windows Studio" - the common Windows IDE, not being nearly the same as XCode - the common Apple IDE.)
This doesn't mean that the program wasn't written in C++, or that the Mac doesn't support C++. There is just "stuff that is different."

An embedded AVR (with 32k/2k of memory) is MUCH MORE DIFFERENT from a Windows PC than a Mac is from Windows, so the difference in programming is also higher. Some things are added or subtracted from the Arduino to emphasize those differences (loop/setup vs main, for example.) Some other things are avoided because they are unlikely to work well (or at all) in the Arduino environment (most of STL, exceptions, dynamic allocation.) Some purists might claim that these mean that it's not "real C++" any more, but 1) Those aren't the people who usually miss-use the "Arduino Language" phrase and 2) They're wrong.

In favor of it being C++:

  • The (infamous) pre-processing of the .ino files to make C++ consists entirely of things that a C++ programmer would have had to do manually in a traditional C++ program (writing prototypes, figuring out library locations, specifying "standard" includes)
  • That pre-processing results only prepending some additional C++ to the file, and modifying the compiler/linker commands. The actual body of the program is not changed at all.
  • A standard C++ compiler is then used to compile the program.

curious48:
"I have an Arduino that I program in Arduino using Arduino" seems fine to me?
I read this as:
"I have an Arduino-compatible board, that I program in the Arduino [redacted], using the Arduino IDE".

You have just made up your mind, haven't you? Every single person on both threads has told you that you are simply wrong, many of them experts in programming and in hardware, both generally and with arduino specifically; and you are nevertheless determined to go ahead and misinform your readers anyway.

But in C++ this is how you change the size of an array:

[c++ changing the size of an array]c++ changing the size of an array](c++ changing the size of an array - Google Search)

… So, this is C++. Will this work? Is this appropriate usage?

Yes, it will work. No, it's not appropriate usage. You only have 2kb of memory, not gigabytes of the stuff. This is not a feature of the language, and you don't get this, or simply refuse to get it, because you have your own personal definition of what the phrase 'computing language' means and want to burden your readers with a privately-held point of view that they are going to have to unlearn later on.

bperrybap writes:

The Arduino IDE provides a development/build environment and defines and provides a runtime operating environment that can be extended further using C++ code, but it sure isn't a language. The actual language being used is C++

Do you mean C? "The actual language being used is C"? (Not "C++").

Oldsteve writes:

"Arduino" is most definitely not a language. The language is C++.

Again, does he mean C?

Paulmurray writes:

Arduino is not a language. It is a hardware platform and a programming environment. The language is simply C++.

Again, does he mean C?

NO! WE EACH SAID WHAT WE MEANT! We are not stupid, we are not ignorant, we are not incapable of expressing what we mean.

The Adruino programming environment uses classes. It uses encapsulation, inheritance, and polymorphism. This is why Serial.println() works, why the HTTP libraries, not to mention every other 3rd-party library, looks the way it does. When you use an adafruit neopixel ring, you instantiate an OBJECT. The OBJECT has METHODS. You are using C++, not C.

It may be true that most arduino programmers on these boards don't use objects in their own code except to call libraries. Personally, I think they should. Please see the page in my sig block, where I discuss this style of programming.

It seems incredibly odd that every single commentor would make this mistake in this pedantic thread. Please explain why they are using the term C++ and not using the term C?

No kidding! It would indeed be very puzzling that every single commenter has made exactly the same mistake. Isn't it so much more likely, dude, that there's only one person who has made a mistake here, and that person is you? You sound like every newb who insists they have found a bug in the compiler because their code doesn't work.

I am more confused than ever.

You are not "confused", you are simply refusing to accept that you are wrong even after being told so repeatedly by people who know quite a bit more about all this than you.

In general, C++ is a superset of C and you can use C constructs. But not the other way around - I've never heard anyone refer to C code as C++ code, unless they're being incredibly casual (like "C/C++"). In this sense, sure, Arduino is "like C++ code".

But now that we're being very technically precise, shouldn't all of the above references to C++ be renamed as references to C?

NO! The arduino programming environment uses objects and references and methods. You cannot do that in C. Which you seem to know perfectly well. The problem isn't that you don't know this stuff. It's that you insist that everybody else call things what you call them. You have decided that "computing language" means something that other people don't mean, something that other people use different words for (platform, API, environment), and that everyone ought to adopt your usage.

If you were to reconcile yourself with using the same names for things that everyone else uses rather than attempting to impose your idiosyncratic vocabulary and view of the world on your readers, you'd find that your job as a writer - communicating - goes quite a bit more smoothly. As it stands, you are going to misinform your readers, making you a bad technical writer in that you will fail at the one job that a technical writer absolutely must do: get it right.

I was beginning to be concerned that I had been a bit harsh in some comments I made in other recent Threads by this OP. But having skimmed this Thread I am no longer concerned.

This whole Thread is just a waste of time. Any information the OP required could easily be found with Google.

It seems to me the length of the OP's posts is in inverse proportion to his level of exertise

...R

Robin2:
I was beginning to be concerned that I had been a bit harsh in some comments I made in other recent Threads by this OP. But having skimmed this Thread I am no longer concerned.

Looks like OP threw in the towel a while back, the rest is just the pundits waxing on in more florid detail...

:wink: