Polymorphism issues with arm-none-eabi-g++/gcc

The following code runs great when compiled with Code Composer Studio(on a TI ARM chip) and avr-g++(on an Arduino chip), in that it writes the desired string or character to the UART.

Yet when I try to compile it with arm-non-eabi for the same ARM chip that I used with CCS, the only thing that works correctly is the Serial.write('a').
The Serial.write("abc") will call the Print::write function, but then that function doesn't know where to go to find write(uint8_t) for the write(*buffer++) call. If I take out the write('a') line, the map file shows that write(uint8_t) won't even be built.

What would cause the compiler to handle the overloaded functions differently from the other two compilers?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//from Print.h
class Print {
... 
    public: 
    virtual size_t write(uint8_t) =0;
    size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
    virtual size_t write(const uint8_t *buffer, size_t size);
}

//from Print.cpp
#include "HardwareSerial.h"
#include "Print.h"
size_t Print::write(const uint8_t *buffer, size_t size)
{
    size_t n = 0;
    while (size--) {
        n += write(*buffer++);
    }
    return n;
}
//from Stream.h
#include "Print.h"
class Stream : public Print {
....//no declarations for any write function
}

//from HardwareSerial.h
#include "Stream.h"
class HardwareSerial : public Stream {
    ...
    public:
     virtual size_t write(uint8_t);//implemented in HardwareSerial.cpp
     using Print::write; // pull in write(str) and write(buf,size) from Print}
}

//from main.cpp
//every header is included for main
main() {
   HardwareSerial Serial();
   Serial.write('a');
   Serial.write("abc");
}
Topic archived. No new replies allowed.