Home AMX User Forum AMX General Discussion
Options

Odd Compiler Error

This gives me a syntax error when compiling and indicates the line above this: "nCblBx_Asignmnt[nCBL_Box] = 0 ;"
DEFINE_FUNCTION fnSystemPowerOff()

     {
     STACK_VAR INTEGER nCBL_Box ;
     
     CANCEL_WAIT 'START_UP_DELAY_1' ;
     CANCEL_WAIT 'START_UP_DELAY_2' ;
     
     nCBL_Box = fnGetCableBoxIndx() ;
     
     if(nCBL_Box)
	  {
	  STACK_VAR INTEGER i ;
	  STACK_VAR INTEGER nLen ;
	  
	  nCblBx_Asignmnt[nCBL_Box] = 0 ;  // <----- this line here
	  nLen = LENGTH_ARRAY(nTVs_using_CableBox) ;
	 
	  for(i = 1 ; i <= nLen ; i++)
	       {//check for other TVs viewing this box if so hand over control
	       if(nTVs_using_CableBox[i] == nCBL_Box)
		    {
		    nCblBx_Asignmnt[nCBL_Box] = i ;
		    //do pop up informing them of control
		    
		    BREAK ;
		    }
	       }//no body's watching so turn off!
	  if(!nCblBx_Asignmnt[nCBL_Box])
	       {
	       SEND_COMMAND dvCATVArry[nCBL_Box],"'POF'" ;
	       }
	  }
     else
	  {

So I comment out "nCblBx_Asignmnt[nCBL_Box] = 0 ;" and it compiles. Hmmm? Why and what's wrong with that line?
DEFINE_FUNCTION fnSystemPowerOff()

     {
     STACK_VAR INTEGER nCBL_Box ;
     
     CANCEL_WAIT 'START_UP_DELAY_1' ;
     CANCEL_WAIT 'START_UP_DELAY_2' ;
     
     nCBL_Box = fnGetCableBoxIndx() ;
     
     if(nCBL_Box)
	  {
	  STACK_VAR INTEGER i ;
	  STACK_VAR INTEGER nLen ;
	  
	  //nCblBx_Asignmnt[nCBL_Box] = 0 ; // <----- now it compiles
	  nLen = LENGTH_ARRAY(nTVs_using_CableBox) ;
	  
	  for(i = 1 ; i <= nLen ; i++)
	       {//check for other TVs viewing this box if so hand over control
	       if(nTVs_using_CableBox[i] == nCBL_Box)
		    {
		    nCblBx_Asignmnt[nCBL_Box] = i ;
		    //do pop up informing them of control
		    
		    BREAK ;
		    }
	       }//no body's watching so turn off!
	  if(!nCblBx_Asignmnt[nCBL_Box])
	       {
	       SEND_COMMAND dvCATVArry[nCBL_Box],"'POF'" ;
	       }
	  }
     else
	  {

So I moved the line a space ot two above where it was and it still didn't compile but when I moved it below the next line it compiles. Any idea why?
DEFINE_FUNCTION fnSystemPowerOff()

     {
     STACK_VAR INTEGER nCBL_Box ;
     
     CANCEL_WAIT 'START_UP_DELAY_1' ;
     CANCEL_WAIT 'START_UP_DELAY_2' ;
     
     nCBL_Box = fnGetCableBoxIndx() ;
     
     if(nCBL_Box)
	  {
	  STACK_VAR INTEGER i ;
	  STACK_VAR INTEGER nLen ;
	  
	  nLen = LENGTH_ARRAY(nTVs_using_CableBox) ;
	  nCblBx_Asignmnt[nCBL_Box] = 0 ;   // <----- this compiles to on this side of nLen = ............
	  for(i = 1 ; i <= nLen ; i++)
	       {//check for other TVs viewing this box if so hand over control
	       if(nTVs_using_CableBox[i] == nCBL_Box)
		    {
		    nCblBx_Asignmnt[nCBL_Box] = i ;
		    //do pop up informing them of control
		    
		    BREAK ;
		    }
	       }//no body's watching so turn off!
	  if(!nCblBx_Asignmnt[nCBL_Box])
	       {
	       SEND_COMMAND dvCATVArry[nCBL_Box],"'POF'" ;
	       }
	  }
     else
	  {

Comments

  • Options
    a_riot42a_riot42 Posts: 1,624
    Its probably because you only have one 's' in nCblBx_Asignmnt. Seriously though, I would get rid of the semi colons and see if it makes a difference. They aren't needed and they are responsible for some weird errors.
    Paul
  • Options
    viningvining Posts: 4,368
    Believe it or not I intentionally spelled it that way, I figured only one "s" was needed to make it readable. Same reason there's no "e".

    Even if I remove the unecassary semi colon it still doesn't work there.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    I vaguely remember something similar coming up before, and the answer (if I'm remembering right) was that assigning an array element right after a variable declaration confuses the compiler, and it thinks it's another variable declaration. Moving it away from the variable declaration resolves the confusion and it works.
  • Options
    viningvining Posts: 4,368
    DHawthorne wrote: »
    I vaguely remember something similar coming up before, and the answer (if I'm remembering right) was that assigning an array element right after a variable declaration confuses the compiler, and it thinks it's another variable declaration. Moving it away from the variable declaration resolves the confusion and it works.

    Hmmm, I guess I don't normally assign an array element after the var declarations now that I think of it, usually just a plain var gets assign directly after.
  • Options
    a_riot42a_riot42 Posts: 1,624
    vining wrote: »
    Believe it or not I intentionally spelled it that way, I figured only one "s" was needed to make it readable. Same reason there's no "e".

    Even if I remove the unecassary semi colon it still doesn't work there.

    Ah, I would never have guessed. Thanks for the elucidation.
    Paul
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    I believe the thread that Dave may be referring to is this one:

    http://www.amxforums.com/showthread.php?665-Baffled-by-a-compiler-error

    The problem comes into play if you have an open left bracket [ as the first character in the first line of code after a variable declaration.

    If you have something like this:
    DEFINE_FUNCTION junction() {
    
       INTEGER one
       
       [dvTP,1] = something
    
    }
    

    The compiler sees it like this and flags it as invalid syntax for declaring a dimensional array.
    DEFINE_FUNCTION junction() {
    
       INTEGER one[dvTP,1] = something
    
    }
    

    A semicolon after the variable declaration fixes the problem.
    DEFINE_FUNCTION junction() {
    
       INTEGER one;
       
       [dvTP,1] = something
    
    }
    
  • Options
    viningvining Posts: 4,368
    ok but what's the reasoning for my error? I use semi-colons and I didn't start with an open left bracket. It seems odd that I haven't been bitten before or that no one else has for that matter as frequent of an occurrence this can be.
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    I don’t see anything wrong with the snippet you posted. Can you post enough of an example that we can compile for ourselves that generates the syntax error? We might stand a better chance of figuring it out.
  • Options
    viningvining Posts: 4,368
    Why certainly!
    PROGRAM_NAME='Test_2'
    (***********************************************************)
    (***********************************************************)
    (*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
    (***********************************************************)
    (* System Type : NetLinx                                   *)
    (***********************************************************)
    (* REV HISTORY:                                            *)
    (***********************************************************)
    (*
        $History: $
    *)
    (***********************************************************)
    (*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_DEVICE
    
    
    #IF_NOT_DEFINED CATV_RACK_BOXES
    dvCATV_Rack1    	= 5001:9:0 // ir 1   
    dvCATV_Rack2     	= 5001:10:0// ir 2
    dvCATV_Rack3       	= 5001:11:0// ir 3 
    dvCATV_Rack4       	= 5001:12:0// ir 4 
    #END_IF 
    
    #IF_NOT_DEFINED vTPcom_CATV
    vTPcom_CATV_1		= 33044:1:0 ;
    vTPcom_CATV_2		= 33045:1:0 ;
    vTPcom_CATV_3		= 33046:1:0 ;
    vTPcom_CATV_4		= 33047:1:0 ; 
    #END_IF
    
    #IF_NOT_DEFINED TIVOs
    dvTiVo_1		= 0:15:0 ;
    dvTiVo_2		= 0:16:0 ;
    #END_IF
    
    #IF_NOT_DEFINED vTIVO_DEVICES
    vTPcom_TiVo_1	     	= 33017:1:0 ;
    vTPcom_TiVo_2	     	= 33018:1:0 ;
    #END_IF
    
    #IF_NOT_DEFINED CATV_MUSCI_UIs
    dvTP_CATVMUSIC_1        = 10001:6:0 ;
    dvTP_CATVMUSIC_2        = 10002:6:0 ;
    dvTP_CATVMUSIC_3        = 10003:6:0 ;
    dvTP_CATVMUSIC_4        = 10004:6:0 ;
    dvTP_CATVMUSIC_5        = 10005:6:0 ;
    dvTP_CATVMUSIC_6        = 10006:6:0 ;
    dvTP_CATVMUSIC_7        = 10007:6:0 ;
    #END_IF
    
    #IF_NOT_DEFINED CATV_UIs
    dvTP_CATV_1            	= 10001:8:0 ;
    dvTP_CATV_2            	= 10002:8:0 ;
    dvTP_CATV_3            	= 10003:8:0 ;
    dvTP_CATV_4            	= 10004:8:0 ;
    dvTP_CATV_5            	= 10005:8:0 ;
    dvTP_CATV_6            	= 10006:8:0 ;
    dvTP_CATV_7            	= 10007:8:0 ;
    #END_IF
    
    #IF_NOT_DEFINED R4_CATV_UIs
    dvR4_CATV_1           	= 10021:8:0 ;
    dvR4_CATV_2           	= 10022:8:0 ;
    dvR4_CATV_3           	= 10023:8:0 ;
    dvR4_CATV_4           	= 10024:8:0 ;
    #END_IF
    
    (***********************************************************)
    (*               CONSTANT DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_CONSTANT
    
    TV_INSTANCE		= 4 ; //normally instance number passed into module, 4 is just a random number pick
    
    (***********************************************************)
    (*              DATA TYPE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_TYPE
    
    (***********************************************************)
    (*               VARIABLE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    
    DEFINE_VARIABLE //nTVSYS_DeBug
    
    VOLATILE INTEGER nTVSYS_DeBug  = 0 ;
    
    DEFINE_VARIABLE //CATV UI ARRAY
    
    DEV dvUI_CATVArry[] = 
         
         {
         dvTP_CATV_1,
         dvTP_CATV_2,
         dvTP_CATV_3,
         dvTP_CATV_4,
         dvTP_CATV_5,
         dvTP_CATV_6,
         dvTP_CATV_7,
         dvR4_CATV_1,
         dvR4_CATV_2,
         dvR4_CATV_3,
         dvR4_CATV_4
         }
         
    DEFINE_VARIABLE //CATV ARRAYS UIs & DEVs
         
    DEV dvCATVArry[6] = 
    
         {
         dvTiVo_1,
         dvTiVo_2,
         dvCATV_Rack1,
         dvCATV_Rack2,
         dvCATV_Rack3,
         dvCATV_Rack4
         }
    
    DEV vTPcom_CableBoxes[6] = 
    
         {
         vTPcom_TiVo_1,
         vTPcom_TiVo_2,
         vTPcom_CATV_1,
         vTPcom_CATV_2,
         vTPcom_CATV_3,
         vTPcom_CATV_4
         }
         
    DEFINE_VARIABLE
    
    VOLATILE INTEGER nUI_TVControlArry[11] 		= {1,2,3,4,5,6,0,1,2,7,8} //which tv indx the UI's control (allow changing on the fly)  
    PERSISTENT INTEGER nCblBx_Asignmnt[6] 		= {1,2,0,0,0,0} 
    PERSISTENT INTEGER nTVs_using_CableBox[11]	= {0,0,0,0,0,0,0,0,0,0,0}
    
    DEFINE_FUNCTION fnDeBug(CHAR iMSG[])
         
         {
         if(nTVSYS_DeBug)
    	  {
    	  SEND_STRING 0,"'TV SYSTEM-',itoa(TV_INSTANCE),' DEBUG: ',iMSG" ;
    	  }
         }
         
    DEFINE_FUNCTION INTEGER fnSelectCableBoxIndx()
    
         {
         STACK_VAR INTEGER i ;
         STACK_VAR INTEGER nLen ;
              
         nLen = MAX_LENGTH_ARRAY(nCblBx_Asignmnt) ;
         for(i = 1 ; i <= nLen ; i++)
    	  {
    	  if(!nCblBx_Asignmnt[i])
    	       {
    	       RETURN i ;
    	       }
    	  }
    	  
         RETURN 0 ;
         }
         
    DEFINE_FUNCTION INTEGER fnGetCableBoxIndx()
    
         {
         STACK_VAR INTEGER i ;
         STACK_VAR INTEGER nLen ;
         
         nLen = MAX_LENGTH_ARRAY(nCblBx_Asignmnt) ;
         for(i = 1 ; i <= nLen ; i++)
    	  {
    	  if(nCblBx_Asignmnt[i] = TV_INSTANCE)
    	       {
    	       RETURN i ;
    	       }
    	  }
    	  
         RETURN 0 ;
         }
         
    DEFINE_FUNCTION fnSystemPowerOff()
    
         {
         STACK_VAR INTEGER nCBL_Box ;
         
         nCBL_Box = fnGetCableBoxIndx() ;
         
         if(nCBL_Box)
    	  {
    	  STACK_VAR INTEGER i ;
    	  STACK_VAR INTEGER nLen ;
    	  
    	  //fnDeBug("'TV-',itoa(TV_INSTANCE),' Shutting down, was using CBox-',itoa(nCBL_Box)") ;
    	  
    	  nCblBx_Asignmnt[nCBL_Box] = 0 ;   //<---  doesn't compile here.
    	  nLen = LENGTH_ARRAY(nTVs_using_CableBox) ;
    	  
    	  nCblBx_Asignmnt[nCBL_Box] = 0 ;   //<---  here no problem?
    	  nTVs_using_CableBox[TV_INSTANCE] = 0 ;
    	  
    	  for(i = 1 ; i <= nLen ; i++)
    	       {//check for other TVs viewing this box if so hand over control
    	       if(nTVs_using_CableBox[i] == nCBL_Box)
    		    {
    		    nCblBx_Asignmnt[nCBL_Box] = i ;
    		    //do pop up informing them of control
    		    
    		    BREAK ;
    		    }
    	       }//no body's watching so turn off!
    	  
    	  //fnDeBug("'TV-',itoa(TV_INSTANCE),' Shutting down, TV now using CBox-',itoa(nCblBx_Asignmnt[nCBL_Box])") ;
    	  if(!nCblBx_Asignmnt[nCBL_Box])
    	       {
    	       //fnDeBug("'TV-',itoa(TV_INSTANCE),' Shutting down CBox-',itoa(nCBL_Box),', D:P:S-',fnDEV_TO_STRING(dvCATVArry[nCBL_Box])") ;
    	       SEND_COMMAND dvCATVArry[nCBL_Box],"'POF'" ;
    	       }
    	  }
         else
    	  {
    	  fnDeBug("'TV-',itoa(TV_INSTANCE),' Shutting down, Had no CableBox control'") ;
    	  }
         //do_push(vTPcom_TV,TV_BTN_MUTE) ; //mute TV    
         //do_push(vTPcom_TV,TV_BTN_IN_1) ; 
         //do_push(vTPcom_TV,TV_BTN_POF) ;
    
         
         //do_push(vdvJAP_SW,BTN_JAP_VID_OFF) ;
         //do_push(vdvJAP_SW,BTN_JAP_DISPLY_OFFSET + TV_INSTANCE) ;
         
         RETURN ;
         }
    
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    If you lose the semicolon after
    STACK_VAR INTEGER nLen
    then it compiles fine.

    I don’t know what is confusing the compiler but it sure looks like you have stumbled into some sort of semicolon bug. <scratching head>

    Personally I find the semicolons as an eyesore and just a waste of time since Netlinx doesn’t use them and your discovery reinforces my feelings. When in Rome do as the Romans. No sense in trying to make Netlinx *look* like some other language.
  • Options
    viningvining Posts: 4,368
    Well it's nice to know I'm not crazy.

    As far as semi colons go I beleive I started using them after seeing other senior programmers using them here on the forums so I in a sense I was doing as the Romans do when in Rome and now they're just a force of habit. I have dabled in other languages but basically I'm still just a dumb electrician so I really only do things that please myself hence my tabs and braces so if other languages write like that then IMHO they're doing things the right way. I would like to be more like you guys but I just cant' do it. I find the way I write code readable and the way everyone else does it to be really hard to follow and unreadable but that's just the way I'm wired or mis-wired as a result of too much partying in my younger rebelous days. Maybe one too many trips or one too many brawls and the resulting blunt trauma to the head?
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    We're all damaged goods in one way or another...
  • Options
    a_riot42a_riot42 Posts: 1,624
    vining wrote: »
    Even if I remove the unecassary semi colon it still doesn't work there.

    How come it didn't work when you did this?
    Paul
  • Options
    viningvining Posts: 4,368
    a_riot42 wrote: »
    How come it didn't work when you did this?
    Paul

    I didn't think I'd have to remove all of them so I just removed the one on the line in question. That's why "unecassary semi colon " is singular not plural. It never dawned on me to remove them all since they've never been a problem before unless I put them where they "really, really" don't belong.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    There are as many bugs in not using the semicolon as there are in using them, so it balances out (see the example GSLogic posted). It's just a matter of preference.

    Personally, I use them because I come from a C++ background, and C requires them; it was always a point of confusion for me leaving them out in Axcess, and was constantly having to go back and delete them when I put them in by habit. I was quite relieved when NetLinx added them in again, or at least made the code compatible if you did, I let the habit reinstate itself.
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    DHawthorne wrote:
    There are as many bugs in not using the semicolon as there are in using them, so it balances out (see the example GSLogic posted). It's just a matter of preference.
    I agree it’s a matter of preference and I can certainly appreciate a semicolon trigger happy right little finger.

    I would like to see the bug example that GSLogic posted about not using semicolons. Can you link to it?

    The only one case that I know of where a semicolon is needed is in the thread I linked to earlier that was started by you.

    The...

    INTEGER x;

    [dvTP,1]...

    thing.

    I personally don’t consider the error that is generated if you don’t use the semicolon in the above case as a bug. The compiler is just doing it’s thing and the reason why it gets confused makes perfect sense. However people want to consider it (bug or not) that’s the only *downside* I know of if we don’t use semicolons.

    On the flip side, the discovery made by vining in this thread is the only case I’ve seen where using semicolons is a bad thing. That one sure looks like a bug to me and I would love to know why the compiler doesn’t like it. If someone figures it out please post a response.
    a_riot42 wrote:
    I would get rid of the semi colons and see if it makes a difference. They aren't needed and they are responsible for some weird errors.

    Can you or anyone else show us another example of semicolons causing weird errors? Or can anyone give another example where using semicolons is necessary?

    To each their own as far as semicolons go. I would just like to know ahead of time how I might get bitten since I don’t use them in Netlinx.

    Thanks.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    Joe Hebert wrote: »
    I agree it’s a matter of preference and I can certainly appreciate a semicolon trigger happy right little finger.

    I would like to see the bug example that GSLogic posted about not using semicolons. Can you link to it?

    My mistake ... my eye must have jumped a few posts ... it was your example I was referring to, right in this thread. :)
  • Options
    viningvining Posts: 4,368
    Since it got me again I figured I'd post it again. You'd think I'd remember!

    Doesn't Compile:
    {
    	  if(nLevel > 0 || nLevel <= MAX_UI_Level)
    	       {
    	       STACK_VAR _sInfoRX sZeroInfoRX ;
    	       STACK_VAR _sInfoGet sZeroInfoGet ;
    	       
    	       sInfoRX[nLevel] = sZeroInfoRX ;
    	       sInfoGet[nLevel] = sZeroInfoGet ;
    	       }
    	  }
    
    Compiles:
    {
    	  if(nLevel > 0 || nLevel <= MAX_UI_Level)
    	       {
    	       STACK_VAR _sInfoRX sZeroInfoRX ;
    	       STACK_VAR _sInfoGet sZeroInfoGet ;
    	       STACK_VAR CHAR nAllowCompile ;
    	       
    	       nAllowCompile = 1 ;
    	       sInfoRX[nLevel] = sZeroInfoRX ;
    	       sInfoGet[nLevel] = sZeroInfoGet ;
    	       }
    	  }
    
    Finding this thread again reminded me that semi colons are partially to blame.

    This also compile (w/o semi's in the declarations):
    {
    	  if(nLevel > 0 || nLevel <= MAX_UI_Level)
    	       {
    	       STACK_VAR _sInfoRX sZeroInfoRX
    	       STACK_VAR _sInfoGet sZeroInfoGet
    	      
    	       sInfoRX[nLevel] = sZeroInfoRX ;
    	       sInfoGet[nLevel] = sZeroInfoGet ;
    	       }
    	  }
    
  • Options
    a_riot42a_riot42 Posts: 1,624
    vining wrote: »
    {
    	  if(nLevel > 0 || nLevel <= MAX_UI_Level)
    	       {
    	       STACK_VAR _sInfoRX sZeroInfoRX ;
    	       STACK_VAR _sInfoGet sZeroInfoGet ;
    	       
    	       sInfoRX[nLevel] = sZeroInfoRX ;
    	       sInfoGet[nLevel] = sZeroInfoGet ;
    	       }
    	  }
    


    Don't you want && and not || here? The level has to be between 0 and MAX_UI_Level and not just one or the other?
    Paul
  • Options
    viningvining Posts: 4,368
    You are absolutely correct and you didn't pick on the semi colon. Thanks!
  • Options
    a_riot42 wrote: »
    && and not ||

    Now that's some fancy logic... :)
  • Options
    a_riot42a_riot42 Posts: 1,624
    Now that's some fancy logic... :)

    Hey, at least it compiles...
    Paul
Sign In or Register to comment.