Search code examples
c++mbed

Mbed wrong long int parsing


    #include <stdio.h>

    int main()
    {
        const char* s = "Number: 420604953084";
        long number;
        sscanf(s, "Number: %ld", &number);
        printf("Result: %ld", number);

        return 0;
    }

This code, compiled on desktop with c++11 (or, for example here) returns correctly:

Result: 420604953084

But compiled with ARM Mbed 6.6 the result is:

(#include <mbed.h>)
...
Result: -301941924

Does anyone have a clue? Unforunatelly, these things are not documented at all in Mbed.


Solution

  • If your the long type is 4 Bytes on your compiler. I think it's reasonable to get and error.

    Please try unsigned long long and the format code "lld".