Sorting out variable conversion warnings ...

cmasoncmason Junior MemberPosts: 123
How do you get the compiler to stop whining about this?:

sinSum[x] = sinSum[x] + intAddend[y] * -1

Generates "WARNING: Converting type [SINTEGER] to [INTEGER] "


I tried:
sinSum[x] = sinSum[x] + TYPE_CAST(intAddend[y] * -1)


And:
sinSum[x] = sinSum[x] + TYPE_CAST(intAddend[y]) * TYPE_CAST(-1)


The compiler seems to whine no matter what I try.

Thanks for looking...

Comments

  • DHawthorneDHawthorne Junior Member Posts: 4,584
    How are you declaring intAddend[] and sinSum[]?

    The fact that you are multiplying intAddend by minus 1 implicitly converts it to an SINTEGER, and any operations on the result forces the result into an SINTEGER as well. There is a rule set to how internal typecasts are done for the purpose of operations, and not all of it is documented, so I have found it by far easier to make sure all my variables are of the same type inside an equation. If I need them to be something else later, I type_cast the *result* while assigning it to its final variable.
  • nickmnickm Blinky Light Aficionado Posts: 152
    This compiles:
    sinSum[x] = sinSum[x] + TYPE_CAST(intAddend[y])  * -1
    
  • cmasoncmason Junior Member Posts: 123
    Declarations:

    VOLATILE SINTEGER sinSum[]
    VOLATILE INTEGER intAddend[]
  • cmasoncmason Junior Member Posts: 123
    nickm wrote: »
    This compiles:
    sinSum[x] = sinSum[x] + TYPE_CAST(intAddend[y])  * -1
    

    Thanks "nickm".

    I'm not sure why I didn't try that. Usually I stumble through how to apply TYPE_CAST. I cleaned a bunch of warnings up after reading a different tread addressing TYPE_CAST but the example I gave you just wouldn't go away.

    It's funny that "sinSum[x] = sinSum[x] + TYPE_CAST(intAddend[y]) * TYPE_CAST(-1)" dosen't work...

    yet "sinSum[x] = sinSum[x] + TYPE_CAST(intAddend[y]) * TYPE_CAST(25)" does.
  • cmasoncmason Junior Member Posts: 123
    DHawthorne wrote: »
    How are you declaring intAddend[] and sinSum[]?

    The fact that you are multiplying intAddend by minus 1 implicitly converts it to an SINTEGER, and any operations on the result forces the result into an SINTEGER as well. There is a rule set to how internal typecasts are done for the purpose of operations, and not all of it is documented, so I have found it by far easier to make sure all my variables are of the same type inside an equation. If I need them to be something else later, I type_cast the *result* while assigning it to its final variable.

    I have gone back and converted INTEGERS (that didn't need to be) to SINTEGERS just to make the warnings go away. But then I would use those SINTEGERS elsewhere in my code and force new warnings, it seemed like would have to go back and convert more INTEGERS... spiraling out of control!

    Maybe I should just drop INTEGERS all together and only use SINTEGERS in place of all INTEGERS that are not likley to exceed 32,768?!?!?
  • DHawthorneDHawthorne Junior Member Posts: 4,584
    cmason wrote: »
    I have gone back and converted INTEGERS (that didn't need to be) to SINTEGERS just to make the warnings go away. But then I would use those SINTEGERS elsewhere in my code and force new warnings, it seemed like would have to go back and convert more INTEGERS... spiraling out of control!

    Maybe I should just drop INTEGERS all together and only use SINTEGERS in place of all INTEGERS that are not likley to exceed 32,768?!?!?

    If you are going to need the sign at any point, that's not a bad solution.
  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,152
    There is also the abs_value that forces sintegers to integers. But you do have an issue if your value is indeed a real negative number.
  • nicholasjamesnicholasjames Junior Member Posts: 154
    SLONG bug

    FYI, SLONG actually has a problem in the compiler that is a bug. See this post I made in another thread about SLONG type casting warnings. It has been reported to AMX...
Sign In or Register to comment.