Go Down

Topic: Standard C++ for Arduino (Read 3411 times) previous topic - next topic

maniacbug

Hi, folks.  I've just finished a port of uClibc++ to Arduino, up on github as the StandardCplusplus library.

This is similar to Andy Brown's excellent work.  However, rather than starting with the original SGI STL, I brought over the more recent uClibc++.  Andy's ohserialstream class was too good to pass up though, so I did include that wholesale, after making a few cleanups.  Also, it installs as a proper library, so no needing to find /usr/lib/avr on your system or whatever.

Frankly, I'm not 100% sure this is a good thing :)  But in case anyone else wants to try it out, the code is there.  Soon we will be on Due, and these more powerful programming constructs will be available to us.  They may have some use on legacy Arduino as well.  Certainly on Mega and 1284P.  The RAM on 328P may limit their usefulness.

Code: (string_vector.ino) [Select]

#include <StandardCplusplus.h>
#include <serstream>
#include <string>
#include <vector>
#include <iterator>

using namespace std;

ohserialstream cout(Serial);

vector<string> strings;

void setup(void)took
{
  Serial.begin(57600);

  strings.push_back("Hello,");
  strings.push_back("world!");
  copy(strings.begin(),strings.end(),ostream_iterator<string>(cout," "));
  cout << endl;
}

void loop(void)
{
}

fat16lib

#1
Dec 25, 2011, 02:19 pm Last Edit: Dec 25, 2011, 05:18 pm by fat16lib Reason: 1
Thanks!

I agree, the Duo and other ARM Arduinos must support Standard C++ templates.

I struggled to get some compatibility with iostreams in SdFat but the flash/RAM size on the 328 limited what I could do.

I have been playing with your port and it is great!

CrossRoads

Hi  maniacbug,
I read what you did, and what Andy Brown posted. I think that not really being a programmer I find the flood of C features a bit overwhelming.  Too many high level features & options.
Maybe I need t build up an LED cube or something and learn how to use some of this stuff to make the patterns to display.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

maniacbug


I agree, the Duo and other ARM Arduinos must support Standard C++ templates.


Yah, all of the GNU ARM toolchains seem to include newlib, so we'll be covered.


I struggled to get some compatibility with iostreams in SdFat but the flash/RAM size on the 328 limited what I could do.

I have been playing with your port and it is great!


Thanks!  Oh yeah, it might not be too hard to make this work with sdfat.  Just have to provide implementations for stdio.h functions, and remove a couple #ifdef's.

Quote

I think that not really being a programmer I find the flood of C features a bit overwhelming.  Too many high level features & options.


Right, and probably totally overkill for a 2K RAM MCU.  As someone accustomed to server clusters, I'm used to having this stuff around and I miss it.  What's less clear is the path for stepping up to this kind of power from the normal Arduino fare of driving hardware.  That's what makes this a bit of an experiment to see if is still has utility for Uno-class Arduino.  If Due is anything like Maple, it will have power to spare, so higher-level constructs will have a place.  Whether it's standard C++, or python or ruby or even php.  As soon as programs get big and complex, they get way more manageable in higher-level languages.

Go Up