Created Fri, 10 Jan 2014 20:39:53 +0000 by pito
Fri, 10 Jan 2014 20:39:53 +0000
It is about a c++ library, so maybe not fully off the topic: I am toying with c++ and <iostream> library. Yes, it eats up 270kB of flash volume, but for educational purposes I have following Q: Any hint what needs to be done the cout, cin will be pointed to serial? (ie. other compilers uses an user defined write(), read() primitives which are then used for cout, cin).
Wed, 15 Jan 2014 17:55:02 +0000
Hi,
I don't think that we provided a full Standard C++ library with the chipKIT compiler distribution. I imagine that you're getting a lot of link errors. What have you got so far?
Wed, 15 Jan 2014 23:51:49 +0000
You need to create some _mon_putc() and _mon_getc() functions that send the serial to where you want, and read it from the same place:
extern "C" {
void __attribute__((used)) _mon_putc(char c) {
Serial.write(c);
}
int __attribute__((used)) _mon_getc() {
while (!Serial.available());
return Serial.read();
}
}
However, I get some interesting results using your sample code:
double x= 1.23;
double y= -3.22;
double z = x + y;
cout << "z= " << z << endl;
which gives:
z= 5.7665e+228
z= 5.7665e+228
z= 5.7665e+228
z= 4.24399e-314
z= 4.24399e-314
z= 1.4854e-313
z= 1.4854e-313
z= 1.4854e-313
rather than the -1.99 I'd expect (and get on Linux). Also, there's some strange buffering thing going on with cin, which stops it working reliably. Not sure what that is yet.