Why does Arduino c++ so much easier

than "real" C++?

the real version has all this object typedef instance public private ->stuff and the whole layout of the program is different too. I bought this 20 buck weather thing, it works, but trying to adapt the software to something i really want has been a nightmare.

The Arduino is programmed in real C++. You can use classes in Arduino programs if you want to but you don't have to. Many of the libraries available for the Arduino use classes but of course, unless you go looking, you may be unaware of it.

The Arduino environment hides some of the requirements of a "real" C++ program such as the need to provide function definitions by doing it for you but that is really just to help you to get started without the need to delve into the intricacies of the C++ environment.

If you want to you do not have to uses the normal Arduino setup() and loop() function model but can write your own main() function and go from there. In summary, you can make an Arduino program as simple or as complicated as you want or need.

UKHeliBob:
If you want to you do not have to uses the normal Arduino setup() and loop() function model but can write your own main() function and go from there. In summary, you can make an Arduino program as simple or as complicated as you want or need.

But you'll end up implementing a very similar construct yourself. As a bare-metal, embedded processor, Arduino has no operating system to "return to" when the task is done.

sevenoutpinball:
than "real" C++?

the real version has all this object typedef instance public private ->stuff and the whole layout of the program is different too.

I use all that and more. I've even got templates and inheritance in my code! :astonished:

Joking aside, the stuff you try to use "real" C++ for is usually much more complicated than what most people are making their Arduinos do. That's why you need more complicated code structures.

sevenoutpinball:
the real version has all this object typedef instance public private ->stuff and the whole layout of the program is different too. I bought this 20 buck weather thing, it works, but trying to adapt the software to something i really want has been a nightmare.

I'm not entirely clear whether you think the simplicity of the Arduino system is good or bad? :slight_smile:

For 20 bucks you probably got what you paid for :slight_smile:

...R

I think simple is great! But what is in those libraries is often incomprehensible to me is all. Why cant they be written where everything is a subroutine starting with some thing like

void subroutine(){
}

so now all i am doing is adding subroutines to my 'sketch'

that would a lot easier.

Why cant they be written where everything is a subroutine starting with some thing like

void subroutine(){
}

Do you mean that the function definition should be in the library so that you can call it using

subroutine();

in your program ? If so then libraries can be written to do that and you already use them in your programs. Where do you think that the code for say pinMode() or digitalWrite() is held ?

I suspect that your confusion comes when a library uses objects which requires an instance of an object to be created before it can be used. One reason for using objects is that you can give them meaningful names. Take for example the Servo library. It allows you to give each servo a name such as leftArm, rightArm etc

Servo leftArm;  //create a servo object to control the left arm
Servo rightArm;  //create a servo object to control the right arm

then you can use the library functions to apply parameters to the named servo such as

leftArm.attach(9);  //control the left arm servo using pin 9
leftArm.attach(10);  //control the right arm servo using pin 10

and

leftArm.write(123);  //move the left arm servo to 123 degrees
rightArm.write(90);  //move the right arm servo to 90 degrees

By using the previously created names the library is able to determine from its name which servo is being controlled and apply the commands to it. The library contains the necessary functions, the names of which are after the full stop in the command

The same principle is used in many libraries

sevenoutpinball:
I think simple is great! But what is in those libraries is often incomprehensible to me is all. Why cant they be written where everything is a subroutine starting with some thing like

void subroutine(){
}

so now all i am doing is adding subroutines to my 'sketch'

that would a lot easier.

I can empathise with that attitude. Classes and objects can seem like a steep learning curve when you first encounter them.

However if you take the trouble to learn about classes you will soon appreciate the extra convenience they bring.

IMHO one of the problems with C++ (and Java and Python, for that matter) is that programs can contain object-oriented code and traditional code all mixed together. With the language Ruby, on the other hand, everything is object oriented. Unfortunately it did not occur to the Ruby folks to provide the convenient "infrastructure" such as Python enjoys.

...R

I'm confused. First OP complains that Arduino is not "real" C++, but then complains about having to use Classes and Objects?

Classes and Objects are the raison d'être of C++. Without them it's just (basically) C.

What's the real problem?

gfvalvo:
I'm confused. First OP complains that Arduino is not "real" C++, but then complains about having to use Classes and Objects?

Classes and Objects are the raison d'être of C++. Without them it's just (basically) C.

What's the real problem?

I think the problem is a lot of people think they should to be able to write complex programs without expending any effort in learning a programming language. Or, they expect all programming languages to use the same syntax and conventions as whatever language they've used in the past.

Regards,
Ray L.

back when i did mvs assembler you got a listing from the compiler that showed where all you instructions and data fields were in the computer. Is there any way I can get something similar. I wouldnt mind at all the protocols of the language if I could just see what is being written to the computer. Makes debugging a snap too.

for example, yesterday i was loading an esp8266 and noticed a lot of verbose data, looked like an old 370 dump almost, go by and thought well maybe thats my program, so I put data items like names in my sketch compiled but could never find those in the compiler messages.

So I dont know.

sevenoutpinball:
back when i did mvs assembler you got a listing from the compiler that showed where all you instructions and data fields were in the computer. Is there any way I can get something similar.

I'm honestly confused: why on Earth would you even care about such things for an Arduino project? Write the code in a way that works and is understandable to you and you shouldn't have to worry about where each machine instruction is stored in memory (or whatever you're trying to do).

What exactly is tripping you up coding in the Arduino IDE? Do you have any specific examples? Are you working on a specific project you can tell us about?

I'm with @Power_Broker. Who gives a sh*t what the compiler does if the Arduino does what you want it to do.

It is possible to get an assembler dump from the compiler but I can't recall how. I know when I did it I reckoned there was no possibility of me writing better assembler code than the compiler produced. A great many person-years of work has gone into the compiler.

Be aware, however, that an ESP8266 is NOT an Arduino product. The ESP8266 folks have hijacked the convenience of the Arduino IDE so that it can be used with an ESP8266. And, from my limited experience it works very well. There is usually a huge chunk of code included in any ESP8266 program to facilitate the WiFi capability and I suspect you would need to be a very serious masochist to investigate that. If you want details about ESP8266 devices look at the ESP8266 Forum - it has all the details and there is a book you can download.

...R

Old habits and expectations die hard I guess. Cheers to all.

You may want “objdump”:
https://forum.arduino.cc/index.php?topic=569453.msg3879673#msg3879673

In general, Arduino programs are so much easier because you are trying to accomplish much smaller tasks.
A general purpose programming language, and the training process for using one, will assume that you want to write something like a web browser that plays multiple videos in independent tabs, using several different compression and communications algorithms.
The Great Idea behind Arduino (somewhat, anyway) is that simpler tasks should be simpler to implement.

Does look interesting.