Home AMX User Forum AMX General Discussion

SLONG vs SINTEGER

I have a question regarding the use of SLONG & SINTEGER which has been bugging me lately. Below is the difference between a sinteger and a slong which I think I understand.
SINTEGER Integer Signed 16-bit -32768 to +32768

SLONG Long Integer Signed 32-bit + 2,147,483,647

In the code below if the structure sAP_Zone[nOutPut].EQ.EQBands] is defined as a sinteger I'll get the wrong value in the array for a negative number typically around the 65535 roll over point, probaly 0 minus the value displayed as a positve number 0 - 10 = 65525 or something along those line. If I change the structure data type to slong it works fine.
structure sPrecis_EQ

     {
     SLONG Balance ;
     SLONG TrebLVL ;
     SLONG BassLVL ; 
     SLONG EQBands[10] ;
     }

The values returned from the Precis DSP for this request are -12db to 12db which is returned as -120 to 120. Now in my mind a sinteger should work fine since it falls well with in the range, why doesn't it.

If that doesn't make any sense for the volume I do use a sinteger and it works fine and its range much greater.
ACTIVE(find_string(iRcvdSTR,"CMD_EQ_BAND",1)):// E  
     {//SO17E1T (90) verifies the gain of EQ band 1 is set to 9 dB for Output 17.
      //SO3E1 2 3T (60 -90 -120) verifies the gain of EQ band 1 is set to 6 dB, band 2 is set to -9 dB, and band 3 is set to -12 dB for Output 3.
     STACK_VAR INTEGER nEQBands[NUM_DSP_BANDS] ;
     STACK_VAR INTEGER nArryIndx ;
     
     cParseTRSH = remove_string(iRcvdSTR,"CMD_EQ_BAND",1) ;//E
     
     if(find_string(iRcvdSTR,"CMD_SPACE",1) == 1)//return often includes a space 1st
	  {
	  cParseTRSH = remove_string(iRcvdSTR,"CMD_SPACE",1) ;
	  }
     nArryIndx = 1 ;
     WHILE(find_string(iRcvdSTR,"CMD_TAKE",1) > 1)
	  {
	  nCount = 1 ;
	  WHILE(iRcvdSTR[nCount] > 47 && iRcvdSTR[nCount] < 58) //between 0 & 9 ; 
	       {
	       nCount ++ ;
	       }
	  nEQBands[nArryIndx] = atoi(get_buffer_string(iRcvdSTR,nCount - 1)) ;
	  if(find_string(iRcvdSTR,"CMD_SPACE",1) == 1)//remove spaces between or at end.
	       {
	       cParseTRSH = remove_string(iRcvdSTR,"CMD_SPACE",1) ;
	       }
	  nArryIndx ++ ;
	  }
	  
     cParseTRSH = remove_string(iRcvdSTR,"CMD_STATUS_BEGIN",1) ;//(
     
     if(find_string(iRcvdSTR,"CMD_SPACE",1) == 1)//return often includes a space 1st
	  {
	  cParseTRSH = remove_string(iRcvdSTR,"CMD_SPACE",1) ;
	  }
     nArryIndx = 1 ;
     WHILE(find_string(iRcvdSTR,"CMD_STATUS_END",1) > 1)//)
	  {
	  nCount = 1 ;
	  WHILE(iRcvdSTR[nCount] > 44 && iRcvdSTR[nCount] < 58) //between - & 9 ; 
	       {
	       nCount ++ ;
	       }
	  sAP_Zone[nOutPut].EQ.EQBands[nEQBands[nArryIndx]] = ATOI(get_buffer_string(iRcvdSTR,nCount - 1)) ;
	  if(find_string(iRcvdSTR,"CMD_SPACE",1) == 1)//remove spaces between or at end.
	       {
	       cParseTRSH = remove_string(iRcvdSTR,"CMD_SPACE",1) ;
	       }
	  nArryIndx ++ ;
	  }
	  
     cParseTRSH = remove_string(iRcvdSTR,"CMD_STATUS_END",1) ;//)
     }

Could some one please explain why slong works and in this case sinteger doesn't.

Comments

  • a_riot42a_riot42 Posts: 1,624
    vining wrote: »
    Could some one please explain why slong works and in this case sinteger doesn't.

    I don't see any reason for it not to work and have similar code using sinteger without any problems. Are you sure it isn't some other issue?

    btw: I notice you have a variable name nArryIndx. Why not call it nArrayIndex rather than nArryIndx?
  • viningvining Posts: 4,368
    a_riot42 wrote:
    Are you sure it isn't some other issue?

    The only thing I'm sure of is that it didn't work as a sinteger and it does work as a slong. Other than that all possibilities are on the table.
    btw: I notice you have a variable name nArryIndx. Why not call it nArrayIndex rather than nArryIndx?
    Just shorter!
  • Joe TJoe T Posts: 10
    From NetLinx Help:

    ATOI
    Converts a character representation of a number to an signed 32-bit integer. The syntax:

    SLONG ATOI (CHAR STRING[ ])


    In the following statement it looks like NetLinx is type casting the return from ATOI as an unsigned integer even when you have it defined as signed.
    vining wrote: »
    sAP_Zone[nOutPut].EQ.EQBands[nEQBands[nArryIndx]] = ATOI(get_buffer_string(iRcvdSTR,nCount - 1))

    You could try wraping ATOI with TypeCast(), it might force NetLinx to look at the destination varible type.

    Joe
  • viningvining Posts: 4,368
    Joe T wrote:
    You could try wraping ATOI with TypeCast(), it might force NetLinx to look at the destination varible type.
    Ok, but if it's a typecast issue caused by atoi why does it work with slong and not sinteger? I have other sintegers in the structure a level or 2 up in the structure that work fine with basically the same code.
  • Joe TJoe T Posts: 10
    vining wrote: »
    Ok, but if it's a typecast issue caused by atoi why does it work with slong and not sinteger?

    Because there is no type conversion when the destination is declared as slong.
    vining wrote: »
    I have other sintegers in the structure a level or 2 up in the structure that work fine with basically the same code.

    Not sure. Just throwing out ideas.

    Joe
Sign In or Register to comment.