C++ Standard compliance in AVR-GCC
Asked Answered
S

2

6

I'm learning to program my Arduino, but I have a pretty solid background in C++, which means that I was very disappointed to find that I couldn't use the C++ Standard Library. I've been looking around trying to find out exactly why that is, and so far the only plausible explanation is that AVR-GCC is not compliant with the C++ Language Standard.

Now, I know that most compilers have minor deviations from the Standard, but I'm thinking that there must be something really big that separates AVR-GCC with GCC, Clang, or any of the other compilers I've used before. Like some massively important feature that's totally missing, or something. There must be a good reason for why I can't use std::vector for instance. It's just way too useful to leave off for no reason.

So what is it? What is the giant hole in the AVR-GCC dialect that makes the C++ Standard Library unworkable on an Arduino? And I'm asking this out of more than just curiosity, because if there are giant holes in the language, then I need to know about them before I go blundering into some undefined behavior that I didn't expect.

Stokeontrent answered 29/4, 2013 at 10:23 Comment(9)
That's the C++, with all its non-compliance, incompatibility, and overall crappy support in embedded world. This is very unfortunate, I know. Being like 13 years into the new century, it feels sometimes like we are still in 90s.Fornicate
It seems to me that most embedded c++ platforms dont ship with the stdlib mostly because no one would really use it anywaysDeeply
@PlasmaHH: Partly, but that sounds more like an excuse.Fornicate
@Haroogan: Maybe, but its a very good one. I would not want to write and maintain a library if nobody is going to ever use it.Deeply
Mostly I think it has to do with the fact that there is 2KB of RAM available, use of new/malloc not really encouraged since you have no OS keeping track of memory, you can easily overwrite and corrupt the stack. The standard library was probably not designed for such constraints and thus not easily ported. The embedded world is a very different place.Lignify
@Fanael: The desktop version of libstdc++ is 1 MB, because well, it's a desktop version. There is nothing magical in the standard which requires it to be that big. Drop all but the C locale, for instance, and you're still Standards compliant.Pugilist
@Fanael - that's what static linking is all about: the linker pulls in the code that's actually used, not the entire library. The size of the library itself has nothing to do with the size of the executable.Certainty
Check https://mcmap.net/q/321076/-vectors-in-arduino/… for info about using std::vector in arduinoTricia
The avr-libc FAQ has an answer to this question.Ludwig
P
-3

AVR-GCC is clearly the work of hobbyists. Essentially, nobody is willing to pick up the hard work of writing a Standard Library implementation. Writing a standard library is not a trivial task for desktop platforms, and the limited capabilities of the Arduino only make it harder.

Pugilist answered 29/4, 2013 at 11:43 Comment(6)
Can you explain why PROGMEM means "hobbyists"?Fun
@angelatlarge: Good compilers don't need a keyword. Additionally, good compiler writes won't end up with "there is no hard and fast rule about where PROGMEM should go". The syntax of C and C++ may some ambiguities, but not at this scale. Syntax is not fuzzy.Pugilist
I am still confused by this claim: is something like volatile evidence of bad compiler design? What about register? Given the fact that AVR is a Harvard-architecture processor with very little RAM but an ability to store data in ROM (with various performance costs associated), I am not sure I see your point about hard and fast rules and fuzzy syntax.Fun
@angelatlarge: The syntax for volatile is very well-defined. Sure, there are multiple places where it's legal, and it does depend on what you are in fact declaring (e.g. for member functions it goes last), but the syntax for volatile is defined by "hard and fast rules", unlike PROGMEM. And yes, register is bad by todays standards (it's flat out ignored). C++ has already reclaimed its cousin keyword, auto, for more useful purposes.Pugilist
@Pugilist One other thing to note is IAR does the exact same thing....and you have to pay for thatDew
OP has clearly stated a very unpopular but true opinion, haha. Jk, I cannot understand the hobbyist part but I am very saddened by the fact that non-runtime STD headers do not work on AVR GCC even today.Etz
F
0

I just ran into problem trying to use a flexible array (variable sized array) in a struct. No compiler complaints, but it just didn't work. I had to change to use a pointer to an array defined outside the struct.

Fruiterer answered 11/11, 2023 at 11:21 Comment(0)
P
-3

AVR-GCC is clearly the work of hobbyists. Essentially, nobody is willing to pick up the hard work of writing a Standard Library implementation. Writing a standard library is not a trivial task for desktop platforms, and the limited capabilities of the Arduino only make it harder.

Pugilist answered 29/4, 2013 at 11:43 Comment(6)
Can you explain why PROGMEM means "hobbyists"?Fun
@angelatlarge: Good compilers don't need a keyword. Additionally, good compiler writes won't end up with "there is no hard and fast rule about where PROGMEM should go". The syntax of C and C++ may some ambiguities, but not at this scale. Syntax is not fuzzy.Pugilist
I am still confused by this claim: is something like volatile evidence of bad compiler design? What about register? Given the fact that AVR is a Harvard-architecture processor with very little RAM but an ability to store data in ROM (with various performance costs associated), I am not sure I see your point about hard and fast rules and fuzzy syntax.Fun
@angelatlarge: The syntax for volatile is very well-defined. Sure, there are multiple places where it's legal, and it does depend on what you are in fact declaring (e.g. for member functions it goes last), but the syntax for volatile is defined by "hard and fast rules", unlike PROGMEM. And yes, register is bad by todays standards (it's flat out ignored). C++ has already reclaimed its cousin keyword, auto, for more useful purposes.Pugilist
@Pugilist One other thing to note is IAR does the exact same thing....and you have to pay for thatDew
OP has clearly stated a very unpopular but true opinion, haha. Jk, I cannot understand the hobbyist part but I am very saddened by the fact that non-runtime STD headers do not work on AVR GCC even today.Etz

© 2022 - 2024 — McMap. All rights reserved.