Announcement

Collapse
No announcement yet.

Warning: 32 bit operand truncated to 16 bits

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Warning: 32 bit operand truncated to 16 bits

    Hi to all,
    this is not really a problem, because the program run correctly, but it is not nice to see this warning at every compilation.
    Moreover if I call the same subroutine "n" times, I find "n" warnings.
    This pieces of program show the warning:
    Code:
    caller:
            mA1 := CalcmA(Mis1, IS1, FS1);
    subroutine:
    func CalcmA(var Mis, var IS, var FS)
    var mA;
        if (Mis < IS)
            mA := 400;
        else if (Mis > FS)
            mA := 2000;
        else
    //        mA := (Mis * 1600 / FS) + 400;
            umul_1616(XX, ABS(Mis), 1600);
            ZZ[0] := FS;
            ZZ[1] := 0;
            udiv_3232(YY, XX, ZZ);
            mA := YY[0] + 400;
        endif
        return mA;
    endfunc
    Instead this one, very similar, does not create the same warning:
    Code:
    caller:
        AllMinSlitta1 := CalcAllPerc(Par[4], 1400);
    subroutine:
    func CalcAllPerc(var All, var Scala)
    var AllPerc;
    //    AllPerc := All * 100 / Scala;
        umul_1616(XX, All, 100);
        ZZ[0] := Scala;
        ZZ[1] := 0;
        udiv_3232(YY, XX, ZZ);
        AllPerc := YY[0];
        return AllPerc;
    endfunc
    May be that both should show the same warning, but is there a limit to 4 warnings in the compiler?
    How can I modify the subroutine to eliminate the warning?

    Best regards, Valter

  • #2
    Hi Valter,

    As you may already know, every variable(var)/constant in 4DGL uses a 16-bit signed integer type with a range of -32,768 to 32,767. If an overflow occurs(value that is outside of the range), the compiler will throw a 'Warning: 32 bit operand truncated to 16 bits'. For example, if you declare a constant:
    Code:
    #constant ABSOLUTE_MAX 32768 // if it's greater than 65535, the warning will show up
    ...and print the value, you'll get the same number with a negative sign. If you change the value of the constant to greater than its unsigned value(65,535), you'll see the same warning show up and the value resets back to zero.

    How can I modify the subroutine to eliminate the warning?
    These forum threads may help:
    https://forum.4dsystems.com.au/node/53562
    https://forum.4dsystems.com.au/node/3362

    I hope this helps.

    Best regards,
    Sherwin
    Last edited by sherwin4D; 4 weeks ago. Reason: 'thread' needs to be in plural form

    Comment


    • #3
      Hi Sherwin
      Solved!
      The problem lies in negative numbers, as you suggest.
      To solve the warning, (which probably gave erroneous results with negative values), I increased all the values of a constant to make them definitely positive.
      Everything works properly and without warnigs.
      Solved and understood, thank you very much.
      Best regards, Valter

      Comment

      Working...
      X