Compare and Contrast C++ and Arduino

In the early 90's I learned some C. At one point, and through most of my programming "career" I've become comfortable with OOP (mostly Visual Basic and Basic for applications). I won't go into all the languages I've done a little programming in but there are quite a few. I'm by no mean an expert.

So, the trouble I'm having isn't on a conceptual understanding of programming. Rather, it's the structure of C++ and its differences with Arduino. Some people are quick to say that Arduino is just C++. Maybe syntactically, but that is all. There are TONS of resources for learning C++ on the net. But, even the most basic tutorials often include specific libraries (std.h for example) as if they are the common goto for C++. Naturally, those tutorials aren't going to say, "Oh, but you can't use this library for Arduino." Sometimes, finding a corollary in Arduino is understandable, at others, it's not so obvious.

printf and formatting was a huge part of what I remember from C. Yet, because we don't have direct access to the computer monitor, I guess it's understandable that whatever library or core has printf in it, won't work with Arduino's serial monitor.

It's also rather obvious that Arduino.cc puts forth a "baby food" variety of functions and libraries for the beginner. That's fine for most people I suppose. But, then when I look at a library file, often times it's like reading a foreign language. So, I know there is more power than what is presented on the Arduino.cc/learning. But, it's also obvious that learning C++ is only partly helpful. You have to know what parts of C++ will work with Arduino and which will not.

There must be a more comprehensive site that lists all the Arduino libraries, classes, methods etc in a hierarchy form... what I've always known as the "object model." How about C++? Ideally, these are usually presented in html. Each "node" then links to another page with more detailed info. A site like this would go along way to eliminating many of the blind spots I (and I assume others) have in my Arduino knowledge.

Short of that, can you compare and contrast C++ with the Arduino IDE language? Is the Atmel software something you think I might find more useful?

The Arduino IDE is C++, with a few additional functions for ease of use. You do not have to use any of them. See this collection of links.

printf() works as expected, but by default lacks support for float variables. It is not hard to link in that support.

Atmel Studio 7 is a monster with an additional learning curve, but professional quality.

I read the link you provided prior to posting the OP. There's much useful information there, some of which was new to me. Many of the links in that thread are to sites specializing in a particular function, such as PWM, or GPS etc. If I can use a tree as an analogy, many of the links in that thread are like the leaves. The Arduino reference page is like the roots and some of the trunk. The core libraries are like the branches. Branches out are generally well documented. The roots and trunk are well documented, however, it feels like there are huge chunks of the trunk I cannot see. Certain things are not in the Arduino documentation (that I've been able to locate), such as the printf() you say works in Arduino.

One of the C++ tutorials I'm reviewing, one of the very basic tutorials, uses a notation I've never known. Specifically, std::cout <<. I can't find the std namespace in arduino. What mention of it I've seen on this forum was in a context with which I was only further confused, rendering it unhelpful information. I've seen a similar notation (not exact) in some of the cpp files I've opened, so I know there's something like it.

This all came up because my IDE kept crashing when I tried to compile an example program (sdfat library). By deleting whole selections of the code, I finally discovered that there was some kind of conflict between the sdfat library and trying to use Serial.print. I had successfully used other example programs in that library with exactly the same includes, that also printed to the serial monitor, so it seemed to contradict my conclusion about the conflict. But in studying the code, I found that while Serial comm had been opened, print() was not used. Instead, the cout notation was used. My next step was to learn the cout notation so I could replace it in the failed compilation sketch. The lack of readily information for that specifically for the Arduino IDE is what prompted the OP.

I once downloaded Studio 6 (I believe). It was very clear that it would indeed require a great commitment. I'd rather not. However, I'm not unfamiliar with such an IDE... just not theirs. Nor am I any more familiar with direct programming of MCU's beyond reading through parts of the Atmel datasheets. :o When I last programmed in depth, I was using MS Visual Studio 2010. Studio 6 reminded me of that on steroids. Yeah, if I can avoid it, I will, but I can see that it might be easier for me to see the big picture?

Atmel Studio 6 is a mess, and not recommended. 7 is much better.

It's not that arduino lacks stdout just that it's sort of meaningless on a micro with no monitor to display on. I have seen people link stdout and stderr to the serial line. Everything C++ is there it's just the differences between a micro controller and a pc computer that make it look a little different.

even the most basic [C++] tutorials often include specific libraries (std.h for example) as if they are the common goto for C++.

they ARE the common goto for C++, and Arduino (in general) doesn't or can't use them. Which is certainly a problem WRT to learning to program the Arduino based on C++ tutorials.

It's mostly a matter of separating the features of the LANGUAGE itself from the libraries that are normally associated with the language. (which is, somewhat, a C/C++ specific issue. C (and C++ to a lesser extent) doesn't have any fancy features (like IO) that aren't provided by "normal" library functions. Other languages (fortran, basic, pascal) have IO keywords and features built in as part of the language.)

"std::cout <<" is a good example. This is just overloading the (existing) "<<" operator ("shift", in C) to work on the C++ class provided by the std stream (?) library. That "<<" is an operator is part of the C language, and that you can overload it to have a different function with a different data type (class) is a C++ language feature, but the actual function that it performs (file/console) output is provided by classes/libraries that are (technically) separate from the language itself. (now, in fact, someone has added this capability to Arduino: Streaming | Arduiniana
(likewise, printf() is available, but isn't "connected" to arduino IO by default, but that can be added as well: how to make printf() work - Frequently-Asked Questions - Arduino Forum)

Certain things are not in the Arduino documentation (that I've been able to locate), such as the printf() you say works in Arduino.

Right. Arduino declines to document standard C, and encourages users to use the Arduino functions rather than the "more confusing" libc functions. You're probably looking for the avr libc manual: avr-libc: AVR Libc

It's not that arduino lacks stdout just that it's sort of meaningless on a micro with no monitor to display on.

In other words, it's EXACTLY that arduino "lacks stdout" :slight_smile:
(and if you're willing to add assumptions like "stdout is the serial port", then you can add stdout back in.)

Atmel Studio 6 is a mess, and not recommended. 7 is much better.

Really? I thought the general wisdom was that Atmel Studio 5.x was a mess, 6.2 is pretty good, and 7 is "a bit new and fragile" 7 won't run on XP :frowning:

I guess I should have said it's not that arduino lacks the ability to use stdout. You're right that it's not there by default but it's pretty easy to add it and use it if you are so inclined.

Really? I thought the general wisdom was that Atmel Studio 5.x was a mess, 6.2 is pretty good, and 7 is "a bit new and fragile" 7 won't run on XP :frowning:

Well, my ranking is simply a bit different.

Studio 5 is a disaster and 6 is a significant improvement.

westfw:
they ARE the common goto for C++, and Arduino (in general) doesn't or can't use them.

That's what I was trying to say. I do understand that point.

It's mostly a matter of separating the features of the LANGUAGE itself from the libraries that are normally associated with the language. (which is, somewhat, a C/C++ specific issue. C (and C++ to a lesser extent) doesn't have any fancy features (like IO) that aren't provided by "normal" library functions. Other languages (fortran, basic, pascal) have IO keywords and features built in as part of the language.)

I know "just enough" about various languages to know that about C. I guess that's why I never bothered to learn it well (it was a numerical methods class requirement my junior engineering year). I can see the benefit for a pro. Visual Basic was OOP and quite powerful, even if not compiled the most efficiently. So, you at least know where I'm coming from.

"std::cout <<" is a good example. This is just overloading the (existing) "<<" operator ("shift", in C) to work on the C++ class provided by the std stream (?) library. That "<<" is an operator is part of the C language, and that you can overload it to have a different function with a different data type (class) is a C++ language feature, but the actual function that it performs (file/console) output is provided by classes/libraries that are (technically) separate from the language itself. (now, in fact, someone has added this capability to Arduino: Streaming | Arduiniana
(likewise, printf() is available, but isn't "connected" to arduino IO by default, but that can be added as well: how to make printf() work - Frequently-Asked Questions - Arduino Forum)

:o :o

Right. Arduino declines to document standard C, and encourages users to use the Arduino functions rather than the "more confusing" libc functions. You're probably looking for the avr libc manual: avr-libc: AVR Libc

BINGO! That's what I was looking for! If I'd seen that, I'd have not posted the OP :slight_smile: Thank you!

In other words, it's EXACTLY that arduino "lacks stdout" :slight_smile:
(and if you're willing to add assumptions like "stdout is the serial port", then you can add stdout back in.)

I am more than willing to accept certain assumptions... especially like that. But, it just isn't obvious coming from the leaves of the tree, in. I can see how someone already proficient in C++ would adapt easily to arduino. I can likewise see how most Arduino users probably never require more than making their robot or weather station work.... that's just not me.

Really? I thought the general wisdom was that Atmel Studio 5.x was a mess, 6.2 is pretty good, and 7 is "a bit new and fragile" 7 won't run on XP :frowning:

Would you recommed Studio 7? You seem to have a good grasp of my "dysphoria." I prefer my XP computer for Arduino, but I have other computers with 7 (pro, and unlimited).

Would you recommed Studio 7?

Yeah, I guess so. Importantly, in context, it is AS7 that adds the "import Arduino Sketch to AS project" command (at least for AVR.)