I'm particularly interested in the "template" element.
If not is there a document that gives you what is covered and not covered ?
I'm particularly interested in the "template" element.
If not is there a document that gives you what is covered and not covered ?
Arduino is programmed in C++ which is compiled by gcc, a full featured (and then some!) compiler. Consequently, if it's in C++, you can use it.
Some of the libraries have stuff missing for space reasons, such as printing floats in sprintf.
So what you're saying is that template is NOT missing.
And the document's not available to the public
So what you're saying is that template is NOT missing.
And the document's not available to the public
What do you mean "the document's not available to the public"? The compiler is Open Source. No only can you read the documentation, you can read the source code that implements the documentation. And you can modify that source code and make your own compiler to have it act however you like.
Yes, avrgcc supports templates.
pamam:
So what you're saying is that template is NOT missing.
And the document's not available to the public
Which document is not available? g++ supports templates and the g++ language specification is available online. Just use Google.
The C/C++ language standards are all available and open to the public.
I was under the impression that it was somewhere on the Arduino website and could not find it?
Thanks all,
pamam
pamam:
I was under the impression that it was somewhere on the Arduino website and could not find it?
Maybe its not, but that does not mean the information is not "available to the public"
I've found multiple versions of the C++ language specifications which use this syntax:
template <> // <=================== this is failing
class mycontainer <char> {
char element;
public:
mycontainer (char arg) {element=arg;}
char uppercase ()
{
if ((element>='a')&&(element<='z'))
element+='A'-'a';
return element;
}
};
with this error message.
exit status 1
'mycontainer' is not a class template
This is part of the 2003 standard since that's when I bought the book yet it is not working.
Can someone confirm that this is NOT part of the gcc g++.
This is called an explicit specialization of the template class. I'm trying to learn C++ again using Arduino gcc but come up short using it.
Thanks,
pamam
You have to define the class template mycontainer before you can specialize it. See Explicit (full) template specialization - cppreference.com, you're missing the "primary template".
C++03 is obsolete, Arduino uses C++11, which is a huge improvement over 03.
As others have mentioned, the GCC avr-g++ compiler that comes with the Arduino IDE fully supports the C++ language, with the exception of the standard library. Templates are fully supported.
Pieter
OK now we're getting somewhere because there are 6 more newer versions. It also explains why it does not work any more. So now, I hope, I can get the right version after pulling a lot of teeth.
Thanks, again for your hep.
pamam
I'm not clear what you're up to here, but if it's just learning C++ in the abstract, you might consider pulling down a nicer IDE and ignore Arduino for your experiments.
pamam:
OK now we're getting somewhere because there are 6 more newer versions.
6? AFAIK, the only newer releases are C++11, C++14, C++17 (and C++20).
FWIW, you can enable a large part of C++17 features for Arduino by editing platform.txt: ArduinoCore-avr/platform.txt at 3055c1efa3c6980c864f661e6c8cc5d5ac773af4 · arduino/ArduinoCore-avr · GitHub
Simply replace -std=gnu++11 by -std=gnu++1z.
wildbill:
I'm not clear what you're up to here, but if it's just learning C++ in the abstract, you might consider pulling down a nicer IDE and ignore Arduino for your experiments.
I agree.
The Arduino IDE is a terrible IDE. When learning a new language, real-time feedback and code completion from a good IDE are a huge advantage. You'll also need a decent debugger, which the Arduino IDE lacks entirely.
On Windows, the obvious choice is Visual Studio. On Linux I use Visual Studio Code with the C/C++ and CMake extensions. CLion is a good choice as well.
wildbill:
I'm not clear what you're up to here, but if it's just learning C++ in the abstract, you might consider pulling down a nicer IDE and ignore Arduino for your experiments.
I don't want to get my code to, (work on VS2019, which I have) then not work on Arduino as well; which has been happening already even with the 2003 version of C++ and the 2003 O'Reilly pocket reference. If the software on Arduino is C++11, I would expect that version of the software to be there. and then this code should compile, but it does not.
class SequenceClass
{
public:
SequenceClass(std::initializer_list<int>);
};
it does not recognize and std::initializer_list
exit status 1
expected ')' before '<' token
Is there a document that has the specification of the Arduino C++11 software that I can get. I waste so much time writing code and trying to get it to run only to find out that it is not supported. I'm banging my head against the wall here. Apparently C++03 is not backwards compatible with C++03 that is on Arduino as well as the C++ 11 is not fully supported either. I have no one but you guys to ask and I hate to bug you all about stuff that should work easily.
Thanks for helping. I guess I need to sit back and think about all this.
pamam
PS Does Arduino have the STD library installed or do I need to include it, and how do I do that??
Sorry guys, I just realized that the STD::initializer_list needs to be replaced with an actual list of ints.
pamam:
I don't want to get my code to, (work on VS2019, which I have) then not work on Arduino as well; which has been happening already even with the 2003 version of C++ and the 2003 O'Reilly pocket reference. If the software on Arduino is C++11, I would expect that version of the software to be there. and then this code should compile, but it does not.SequenceClass(std::initializer_list<int>);it does not recognize and std::initializer_list
exit status 1
expected ')' before '<' token
You don't have access to the standard library on AVR-based Arduino. You can use them on pretty much all newer ARM-based Arduinos, as well as on ESP* boards.
I don't think there are any inherent problems that stop you from you from using the standard library, though, AVR is just not popular enough for the GCC folks to maintain a version of the standard library for it, especially since AVR microcontrollers are very limited, so heavy use of dynamic memory or exceptions are a no-go.
You can get third-party ports of the standard library, though, I maintain Arduino-Helpers for my projects, it contains some of the standard library headers, including initializer_list. It's just a port of the standard GNU libstdc++. An alternative would be ArduinoSTL.
pamam:
Is there a document that has the specification of the Arduino C++11 software that I can get. I waste so much time writing code and trying to get it to run only to find out that it is not supported. I'm banging my head against the wall here. Apparently C++03 is not backwards compatible with C++03 that is on Arduino as well as the C++ 11 is not fully supported either. I have no one but you guys to ask and I hate to bug you all about stuff that should work easily.
If you stick to the C++11 standard, most code that can be made to compile on Visual Studio can be made to compile on Arduino, provided that you don't use any non-compatible libraries or code that calls into the OS.
If your goal is to run it on an AVR-based Arduino, limit the standard library usage (especially dynamic containers), and keep in mind that exceptions are not supported.
If you learn C++ in Visual Studio, you'll have no problems applying the concepts you learned to Arduino later. I would strongly discourage using the Arduino IDE for learning C++.
Unless you're forced to work with legacy pre-C++11 code bases, I see absolutely no value in learning C++03 in 2020.
If you want to learn C++ for Arduino, follow a C++11 book/guide/tutorial. C++14 or C++17 are fine too, they were incremental updates, and as mentioned earlier, you can use them on Arduino by enabling C++14 or C++17 support in the platform.txt file.
Useful resources:
Hi again PieterP,
Thanks for that very clear answer. I think I will do just that use either C++11, C++14, or C++17 and modify the .txt file you mentioned. Yes also I was afraid that std library would be a heavy load on the AVR. I've seen a few books on all three version so I can chose the one that is a little less expensive than $100+. I'm extremely grateful that you did not blow me off after that ranting I was doing.
Thanks a million
pamam
If you're not prepared to spend large amounts of money on books, I think learncpp.com would be a good place to start. I haven't followed it myself, but I've heard positive things about it. If you prefer a book, many of the popular C++ books are floating around on the interwebs in PDF form, you should be able to find them with some clever googling (using "filetype:pdf", for instance).
About the standard library: some parts are not really suited for small microcontrollers (like std::map, std::list, etc.), while many other things like the header or std::array are not an issue at all. The biggest problem is dynamic memory usage, especially if you're resizing containers.