Getting Linting and errors

Getting these linting error on Mbed Studio v14.3 compiled with gcc-arm. Compilation is done without error proven in serial monitor.

How do I solve this? Read this occur on previous version but fixed this version.

try with std::vector

and I would not use iostream if I were you.

Hello Muhammad,

I agree with Ladislas. The iostream is a huge beast. I don’t know your target chip but when I tried to compile your code with GCC_ARM (for debug) for a NUCLEO-F411RE it could not fit into its 512kB flash. The linker complaint was: region FLASH overflowed by 40732 bytes.

If you would like to use the iostream syntax for printing anyway then you can overload the << operator for the FileHandle class, for example as below. That will introduce just a very small overhead as opposed to the iostream.

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

#define endl "\r\n"

FileHandle* cout = mbed_file_handle(STDOUT_FILENO);

// Overloaded to print C style strings
FileHandle &operator<<(FileHandle& obj, const char* arg)
{
    obj.write(arg, strlen(arg));
    return obj;
}

// Overloaded to print "int" type
FileHandle &operator<<(FileHandle& obj, int arg)
{
    char buf[5] = { 0 };

    sprintf(buf, "%i", arg);
    obj.write(buf, strlen(buf));
    return obj;
}

// Overloaded to print "float" type
FileHandle &operator<<(FileHandle& obj, float arg)
{
    char buf[10] = { 0 };

    sprintf(buf, "%f", arg);
    obj.write(buf, strlen(buf));
    return obj;
}

int main()
{
    vector<int> a = {4, 3, 2, 1};

    for (auto key: a) {
        *cout << "key = " << key << endl;
    }

    return 0;
}

I have only used the online IDE, so studio is quite new to me. I just find out iostream is the one breaking armc6 compiler. Looks like it taking much memory on gcc.

Interesting answer, thanks. is template not supported?

is template not supported?

Templates should work. The code above is using template to specify the the vector’s type and compiles fine. There are also no linting errors reported.