Warning : <__c.0> may be used before being set

23 Feb 2010 . Edited: 23 Feb 2010

I would like to use the cout stream (for some inline logging code) and found this code to redirect cout to stdio:

#include "mbed.h"
#include <iostream>

class OutputBuffer : public std::streambuf {
public:
    OutputBuffer() {
        setp(0, 0);
    }

    virtual int_type overflow(int_type c = traits_type::eof()) {
        return fputc(c, stdout) == EOF ? traits_type::eof() : c;
    }
};

int main() {
    printf("Hello world\n");

    OutputBuffer ob;
    streambuf *sb = cout.rdbuf(&ob);
    cout << "Hello world again\n";
}

It works, which is great, however the compiler generates some warning messages:

"<__c.0> may be used before being set" in file "/opt/RVDS4/RVCT/Data/4.0/400/include/unix/ostream"
"<__c.0> may be used before being set" in file "/opt/RVDS4/RVCT/Data/4.0/400/include/unix/ostream"
"<__c.0> may be used before being set" in file "/opt/RVDS4/RVCT/Data/4.0/400/include/unix/streambuf"

Are they indicative of a problem and could they be suppressed if not?

Thanks
Daniel

01 Mar 2010

Hi mbed team

I hope you don't mind if I bump this, I know there has been a lot of travelling and work back at base with the compiler as well.

Is it fair to say you are not supporting streams and other things that are possible in the compiler but not desirable on the platform?

Thanks
Daniel

01 Mar 2010 . Edited: 01 Mar 2010

Hi Daniel,

Whilst I wouldn't encourage streams (or use of any of the STL), we are not actively trying to stop/break them, so i'd consider this a bug. Note, the example can be simplified to the following and still generate the warning:

#include <iostream>
int main() {
    std::cout << "Hello world\n";
}

I've filed a low priority ticket to look at this when appropriate, as it may be hiding something else and shouldn't be giving this behaviour.

Thanks,
Simon

04 Mar 2010

Thanks Simon

I reckon using iostream is costing me 8000 bytes which is quite a lot out of my precious 32K. I need to work out if I'm going to have enough space for my code plus the lwip library, but have run into problems with using malloc to work that out (see here). Igor's python script is great but doesn't work with more than one library (mbed included). Any chance of those compiler stats yet?

Regards
Daniel