[SOLVED] Arduino language

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:

Nick, the post you have linked (programming - Classes and objects: how many and which file types do I actually need to use them? - Arduino Stack Exchange) is amazingly detailed and unbelievably helpful!

I have these questions:

Do you have a similar reference for the "build process" itself? For example, it is clear that at the point of your third bullet point there is a "temporary compilation folder". What is the program that actually builds it?

It must be a C++ compiler (like gcc). I googled this and found: " is passed directly to a C/C++ compiler (avr-g++)."

Is it avr-g++ in every case? Or can other compilers be used at this step?

I find it extremely hard to understand why the 2000 words in your write-up and linked "more information" do not mention avr-g++ even a single time, if, in fact, it is the compiler actually used after the above compilation steps in every case.

Here are more questions:

-> If I manually performed the steps 1-10 could I then pass them to avr-G++ myself and receive a compiled program? Why or why not?

-> What is avr-g++ (Google search "what is avr-g++")?

People are accusing me of not googling. The first Google result is "avr-g++: command not found" while compiling, using Arduino IDE 1.6". It does not say what avr-g++ is.

The second link is "c++ - Using Arduino Libraries with AVR-G++ - Stack Overflow" and writes "Is there a simple way to use libraries intended for the Arduino IDE with the C and assembly code I write for AVR-G++/AVR-GCC?" and does not define what AVR-G++ is.

The third link is bizarre and seems to be a man page for gcc. Does the Arduino just use gcc directly?

If so why can't people just use gcc directly, after performing steps 1-10 from your write-up?

Why aren't there more Arduino-templating-language compatible IDE's other than the Arduino IDE, if we define the Arduino-templating-language as simply meaning "perform steps #1-#10 to receive C++ files ready to hand off to gcc"?

C++ is a standard language based on standards. It is not considered standard to be able to compile it using only a single compiler. Why can't other compilers be used, other than gcc (if indeed that is what is being used)?

For example, an alternative to gcc is clang (LLVM). If I personally perform steps 1-10 can I just pass it off to clang? Why or why not?

Finally, based on the fact that steps 1-10 are performed how would you feel about my using the nomenclature "Arduino templating language" or to be more explicit "Arduino C++ templating language" which would make it clear that:
1: Code produced in the Arduino templating language is not ready to be passed on to GCC directly. There is a bit of translationn involved.
2: It is a light translation that results in C++ code that is ready to be passed to the compiler.
[I rejected this possibility.]

This would make it clear that while a "templating language" Arduino qua language is essentially C++. The only thing that makes it a (templating) "language" as opposed to wizard, is that it is written in text form, rather than by clicking buttons in a wizard. [rejected]

Would this usage be accurate? Thank you.

Example of usage

Ambiguous:
"I have an Arduino that I program in Arduino using Arduino".

Explicit:
"I have an Arduino-compatible board, that I program in the Arduino templating language, using the Arduino IDE".

In other words, "Arduino language" should be written "Arduino templating language" or "Arduino C++ templating language." [rejected]

It would make it clear that it is a templating language that simply "turns into" C++ after steps 1-10 are performed. [rejected]

Thoughts?

Explicit:
"I have an Arduino-compatible board, that I program in the Arduino templating language, using the Arduino IDE".

How aout "I have an Arduino-compatible board that I program using the Arduino IDE" ?
The reason that you don't see the language explicitly called out is that hardly anyone cares.
If you must, it would be: "I have an Arduino-compatible board that I program in C++ using the Arduino IDE"

It would make it clear that it is a templating language

Everyone keeps telling you that it's C++, and any other wording is worse. You say our answers are "very helpful", but you remain stubbornly unconvinced of that basic fact, and are making your description worse and more obscure the harder you try.

I give up.

westfw:
"I have an Arduino-compatible board that I program in C++ using the Arduino IDE"

This is incredibly clear. :smiley: :smiley: It's too bad the Arduino web site and reference documents don't say this! It means that calling it a 'sketch' is a distinction without a difference.

Some people here have been acting like it's my fault for being confused, but it's not. The Arduino project went through the lengths of inventing the word "sketch" for "C++ program' (if your suggestion is accurate.) :-[

You write:

I have an Arduino-compatible board that I program in C++ using the Arduino IDE

But where Arduino (the project) call its IDE an IDE with built-in C++ compiler? Here is a picture on the front page:
![

How would they know that if they didn't find some simple algorithm in "Arduino sketch" they can just copy it over from C and C++? :-[

Why doesn't Arduino include any C or C++ tutorial? :-[

It seems like it is trying very hard to hide what is "under the hood." There isn't the most passing reference to it anywhere. In fact, even the word pointer or reference or stack or heap or malloc or free or class or any of that stuff is completely left out of the tutorials. :-[

I was given no indication that I was coding in C++ or C rather than just something where all the syntax guesses I made happened to work. I realize that C++ is "scary" but as someone who has programmed in C and C++ the only thing I saw was that anything I guess still worked. :-[

But the same is true of Java and Javascript. So for whatever reason, this is very poorly communicated. :-[

Plus, the language reference tells you about Goto: Arduino - Home but not classes? There isn't a single example of any talk about pointers or references or anything like that? :-[

I mean I realize that this stuff is "scary" but it makes people think that Arduino is a subset of C or C++. It lets people make sketches without ever being told they're C or C++ programmers. They never need to learn those skills. :-[

So it's a "subset" but not because of the limitations of the "language" - but rather because those things are never taught or emphasized. :-[ :-[

I'm sorry I didn't get this, but I'm a victim of the instructions, I swear! With all this talk of an Arduino language, I thought there was one!

That is the front page. I click "What is Arduino" and unfortunately, this is what I get.

Let's zoom in here:

Do you see the source of my confusion? :smiley:

If instead I click "learn arduino" I get this:

You act like it's my fault for being confused!

If you are accurate and it is correct to write:

"I have an Arduino-compatible board that I program in C++ using the Arduino IDE"

Then "Arduino software" should read differently.

Currently:

ARDUINO SOFTWARE
You can tell your Arduino what to do by writing code in the Arduino programming language and using the Arduino development environment.

Correctly:
ARDUINO SOFTWARE
You can tell your Arduino what to do by writing code in the C++ programming language and using the Arduino development environment.

And the "Learn arduino" reference I linked should, at some point, mention the word C++ don't you think? :smiley: Have a read: https://www.arduino.cc/en/Guide/Introduction

I know C++. I've programmed in C++. On Linux and Windows.

When I started programming Arduino with a friend, whenever they would get stuck I would just try writing C++. Simple things - like, "how do I check if it's odd"? I don't know try "if (value % 2)" should work, this will tell you if dividing by 2 has a remainder.

Well, everything like that that I tried seemed to work. 8) But that didn't mean to me that Arduino is C++ anymore than it means Java is C++ just because many things a C++ programmer who just guesses and tries, will happen to work. Nor is Objective-C the same as C++. Nor is Go the same as C++. But Arduino is different - it really is C++.

So it turns out that Arduino literally is C++(not some subset). Not C-like, or "like C++" or "based on C++". Literally C++. But you need to be told this. It's kind of hidden away.

At no point in the introductory learning materials do you find any reference to C++, even though it is what you are writing.

In fact, isn't this odd, considering that you could copy and paste any code from any C++ site that does some kind of arithmetic or similar?

Here is an example of low-pass filter in C:

void lowPassFrequency(double* input, double* output, int points)
{
    double RC = 1.0/(CUTOFF*2*3.14); 
    double dt = 1.0/SAMPLE_RATE; 
    double alpha = dt/(RC+dt);
    output[0] = input[0]
    for(int i = 1; i < points; ++i)
    { 
        output[i] = output[i-1] + (alpha*(input[i] - output[i-1]));
    }
}

so, assuming CUTOFF and SAMPLE_RATE are defined, that will just work the same, take two arrays and the number of points, and that's it.

But why would someone learning Arduino know that based on the sample code, since they're not even told that Arduino is C/C++? :-![

How would they know that if they didn't find some simple algorithm in "Arduino sketch" they can just copy it over from C and C++? :-[

Why doesn't Arduino include any C or C++ tutorial? :-[

It seems like it is trying very hard to hide what is "under the hood." There isn't the most passing reference to it anywhere. In fact, even the word pointer or reference or stack or heap or malloc or free or class or any of that stuff is completely left out of the tutorials. :-[

I was given no indication that I was coding in C++ or C rather than just something where all the syntax guesses I made happened to work. I realize that C++ is "scary" but as someone who has programmed in C and C++ the only thing I saw was that anything I guess still worked. :-[

But the same is true of Java and Javascript. So for whatever reason, this is very poorly communicated. :-[

Plus, the language reference tells you about Goto: Arduino - Home but not classes? There isn't a single example of any talk about pointers or references or anything like that? :-[

I mean I realize that this stuff is "scary" but it makes people think that Arduino is a subset of C or C++. It lets people make sketches without ever being told they're C or C++ programmers. They never need to learn those skills. :-[

So it's a "subset" but not because of the limitations of the "language" - but rather because those things are never taught or emphasized. :-[ :-[

I'm sorry I didn't get this, but I'm a victim of the instructions, I swear! With all this talk of an Arduino language, I thought there was one!

1 Like

westfw:
I give up.

Don't waste you time with this guy.

LOOK at his other posts.

He asks questions then basically tells you you are wrong. :roll_eyes:

Having just read the OP's latest posts, I give up too. You can lead a horse to water.........

@curious48 , perhaps your time would be better spent learning the language and it's usage, then practising, than writing technical articles on something you appear to know very little about.

OldSteve:
@curious48 , perhaps your time would be better spent learning the language and it's usage, then practising, than writing technical articles on something you appear to know very little about.

:smiley:

There you go, I should "learn the language", technically, I've I've programmed C and C++ before the Arduino language existed, so since Arduino isn't a language, I've programmed the language before it existed :smiley: :smiley: :smiley: :smiley:

Seriously though:

There is a ton of muddying the waters done by the Arduino project, and the Wikipedia article makes clear why: "The goal was to create low cost, simple tools for non-engineers to create digital project".

So for the record: the questions I've posed in this thread are completely justified. Arduino goes out of its way to hide the fact that there is no such thing as the Arduino programming language.

Arduino programs are a minimally processed set of C/C++ files. ~~ I think I was asking a question about why the emperor isn't wearing any clothes.~~ :smiley: :smiley:

But don't act like it's my fault for being mislead, asking and wanting to know.

Anyway, I began this thread by quoting (this wasn't directed at me):

>"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.""

And part of this doesn't tell the whole story. It's not that "because they never took the time to actually understand what Arduino is and is not."

In my case, I would rewrite the above as:

"The Arduino language is the Arduino project's name for C and C++. They never use the latter phrasing to refer to Arduino code, and go so far as to call programs sketches."

This would clearly identify what is actually going on! :smiley: :smiley:

Thanks for all of your answers, everyone.

[Edit: struck out my whining]

I found this great resource:

Which includes several answers saying the same thing as is said here. The questioner, like me, had experience with several programming languages, like JavaScript, PHP, Java and Visual Basic, but wrote asking "C++ vs. The Arduino Language: what are the advantages of each language when using the Arduino?", which is, obviously, a nonsensical question.

As happened in our threads here, several people corrected them.

A Professor stated "In any case, it won't harm you to start using the arduino language and the arduino IDE for a few days to get familiar with the arduino hardware and then move to C/C++ with Eclipse for really developing your project", again, repeating the nonsensical nomenclature.

Curious you are right: more you say nonsense, the more you feel Intelligent, but you're only stupid and ridiculous..
Yes Arduino is a true language as my feet are interplanetary vehicles.

Languages are Basic, PHP, Pascal, Ada, C, C ++, etc.

Wiring / Arduino is ONLY a SET of FUNCTIONS and CLASS writen in C or C ++, and an IDE. An IDE is not a language

Wiring / Arduino is ONLY a SET of FUNCTIONS

Please STOP, STOP, STOP to say nonsence.

Can a moderator could destroy this topic which is dangerous for beginners.
It is impossible to leave write such absurdities.

1 Like

I've now written up what I've learned in this "35-second Arduino language reference for expert programmers".

I don't have further questions on this issue and am closing this thread. For those who contributed helpfully, thank you.

The Arduino Language is a simple macro that creates a loop that a microcontroller runs forever.

I stopped reading it at that point.

AWOL:

The Arduino Language is a simple macro that creates a loop that a microcontroller runs forever.

I stopped reading it at that point.

I try to help people who want to learn. But I have no time at all for people who want to teach without taking the trouble to learn first.

It is very disheartening to find that all that has been said by many people in answer to this OPs several Threads is reduced to such an inaccurate and misleading summary.

"Snake oil" salesmen have not all disappeared, it seems.

...R

If so why can't people just use gcc directly, after performing steps 1-10 from your write-up?

They can. That's the whole point of Arduino. Doing those ten steps yourself is not intuitive and is more than many beginners can understand. Arduino is a program that does those things for you so your don't have to. You can program your Arduino board even if you haven't downloaded a single thing from Arduino. You don't need the IDE, or any part of what comes with the Arduino package. But then you have to put the tool-chain together yourself. That's how it was done before Arduino came around.

1 Like
  • These two functions must be present. setup() contains the code that the microcontroller runs once upon being powered, the loop() function contains the code that loops tightly forever.

loop is only tight if you write it tight. If you write a bunch of blocking code in there then it won't loop so tightly anymore.

And you can most definitely have your own main function if you don't want to use the setup / loop paradigm.

It is simply passed to a C++ compiler to finish compilation.

Nope. The C++ compiler doesn't finish the compilation for the IDE, it does the WHOLE compilation procedure. What the IDE does before that is pre-processing, not compilation.

In practical terms the basic Arduino program structure is not event-driven.

That depends on how you write your code. Whether or not it is event driven has nothing to do with it being Arduino or not. You can write event driven code with Arduino.

The loop() should poll heavily for any event it needs, blocking completely.

Polling a pin does not require b locking. Read the pin and move on.

All functions are blocking.

No, they're not. You're on a single core, so you can't run two instructions at once, but that doesn't mean all the code is blocking.

The rest of the arduino.h header file contains other functions commonly used. From a language specification perspective it is more precise than the official documentation.

I'll give you this one. Documentation is scant around here. Your best bet to understand any library is to understand the language and look at the source code.