Home AMX User Forum AMX General Discussion

SINTEGER Arithmetic problems

Perhaps I'm missing something simple here.
I'm trying to subtract 1,440 (the minutes in a day)
from a SINTEGER. My code goes something like this:

SINTEGER nX; //Variable definition
.
.
.
if (some condition) {
nX = nX - 1440;
}
This produces a warning that I am "converting type [SINTEGER] to [INTEGER]"

I've tried Defining a SINTEGER constant to equal 1440 and subtract that, but
then it complains that my SINTEGER constant is a conversion.
I've tried to putting TYPE_CAST ( ) around various parts of the equation, but
may not be using it correctly.

Any suggestions or insights would be MOST appreciated!!

And if there's documentation I have missed that explains my confusion
I would DEFINITELY appreciate a pointer to said documentation.

-Preston |8-)

Comments

  • truetrue Posts: 307
    A lot of the type stuff gets very confusing, especially with sinteger/long/slong and conversions of types thereof. I really wish NetLinx supported real casting, but...

    In NetLinx, integrals 256 or higher seem to act like "integer." You need to type_cast your number, so
    if (some condition) {
    nX = nX - type_cast(1440);
    }
    

    Yet another NetLinx compiler bug. Sigh...
  • Joe HebertJoe Hebert Posts: 2,159
    Sharpdog wrote:
    I've tried Defining a SINTEGER constant to equal 1440 and subtract that, but
    then it complains that my SINTEGER constant is a conversion.
    That?s the route I would try to take instead of type casting an arbitrary number. I?m guilty of using constants liberally.

    How did you define your constant?

    If you did this:
    DEFINE_CONSTANT
    
    SINTEGER Minutes = 1440
    

    Then you should get a Converting type [SINTEGER] to [INTEGER] warning. I can?t get the SINTEGER constant is a conversion error but that?s just an aside.

    If instead you do this:
    DEFINE_CONSTANT
    
    SINTEGER Minutes = {1440}
    

    Then the compiler is satisfied and you can use a constant for your math without any type casting.

    Just wanted to throw that out there as an option.
  • jweatherjweather Posts: 320
    Also keep in mind that some of the warnings have the line numbers off by one, so make sure the warning is really about the line that you're looking at (for example by commenting out the other lines around it).
  • DHawthorneDHawthorne Posts: 4,584
    jweather wrote: »
    Also keep in mind that some of the warnings have the line numbers off by one, so make sure the warning is really about the line that you're looking at (for example by commenting out the other lines around it).

    Off by one would be nice. I've seen them off by 20 or 30 because of bad tracking of include files.
  • DHawthorne wrote: »
    Off by one would be nice. I've seen them off by 20 or 30 because of bad tracking of include files.

    Then there's always the fun error messages with no line numbers:
    ERROR: (0): C10580: Internal Error: Major system error occurred during code generation

    By the way, nice job Joe on the the braces advice. I think I've always type_cast in that situation.

    --John
  • SharpdogSharpdog Posts: 7
    Thank You for the help!

    Thank You to all of you for your posts especially true and Joe for their solutions.

    AMX Programming.... Never a dull moment!!

    -Preston |8-)
Sign In or Register to comment.