Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By tma
#52069 Thanks!

//To clarify:
unint32_t xVariable = 14000000UL;
unint64_t yVariable = 14000000000ULL;

//This prints OK:
Serial.println(xVariable);
//This fails:
Serial.println(yVariable);
User avatar
By martinayotte
#52107 Of course Print class doesn't support uint64_t type.
Trying to split the print into two 32bits parts, it seems that even gcc has trouble handling 64bits.
After digging the issue, trying also the famous BigNumber library, I've only figured out the following way to handle it :
Code: Select all//    BigNumber l = (BigNumber)14000000000ULL;
    BigNumber l = (BigNumber)1400000 * (BigNumber)10000;
    l.printTo(p);
    p.println();

As we can see, the commented line isn't working too, gcc seems to handle this constructor as 32bits too, so I had to use the second declaration to create the BigNumber and make it working.
User avatar
By jcmvbkbc
#52112
martinayotte wrote:it seems that even gcc has trouble handling 64bits.

gcc-4.8.5 built with esp-open-sdk doesn't seem to have any trouble. The following example compiles just fine:
Code: Select all$ cat bn.cpp
void f(int);
void f(unsigned long long);

void g(void)
{
        f(14000000000ull);
}
$ esp-open-sdk/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++ -fno-exceptions -Os -S bn.cpp
$ cat bn.s
        .file   "bn.cpp"
        .text
        .literal_position
        .literal .LC0, 1115098112, 3
        .align  4
        .global _Z1gv
        .type   _Z1gv, @function
_Z1gv:
        l32r    a2, .LC0
        l32r    a3, .LC0+4
        addi    sp, sp, -16
        s32i.n  a0, sp, 12
        call0   _Z1fy
        l32i.n  a0, sp, 12
        addi    sp, sp, 16
        ret.n
        .size   _Z1gv, .-_Z1gv
        .ident  "GCC: (crosstool-NG crosstool-ng-1.22.0-55-gecfc19a) 4.8.5"

martinayotte wrote:After digging the issue, trying also the famous BigNumber library, I've only figured out the following way to handle it :
Code: Select all//    BigNumber l = (BigNumber)14000000000ULL;
    BigNumber l = (BigNumber)1400000 * (BigNumber)10000;
    l.printTo(p);
    p.println();

As we can see, the commented line isn't working too, gcc seems to handle this constructor as 32bits too, so I had to use the second declaration to create the BigNumber and make it working.

Which BigNumber library are you referring to? Could it be that there's no BigNumber constructor that accepts unsigned long long?
User avatar
By martinayotte
#52116 @jcmvbkbc, you're right !
I didn't dig enough ...
The Nick Gammon BigNumber didn't have a 64bits constructor, but it have a string constructor has a work around.
Code: Select allBigNumber l = (BigNumber)"14000000000";

Also, I did something wrong while testing plain uint64_t arithmetics, the following code is working :
Code: Select all    uint64_t l = 12345678901ULL;
    Serial.print(uint32_t(l / 100000));
    Serial.println(uint32_t(l % 100000));

So, gcc isn't guilty at all ... :ugeek: