Odd Compiler Error
vining
Posts: 4,368
This gives me a syntax error when compiling and indicates the line above this: "nCblBx_Asignmnt[nCBL_Box] = 0 ;"
So I comment out "nCblBx_Asignmnt[nCBL_Box] = 0 ;" and it compiles. Hmmm? Why and what's wrong with that line?
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 ; 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 {
0
Comments
Paul
Even if I remove the unecassary semi colon it still doesn't work there.
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.
Ah, I would never have guessed. Thanks for the elucidation.
Paul
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:
The compiler sees it like this and flags it as invalid syntax for declaring a dimensional array.
A semicolon after the variable declaration fixes the problem.
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.
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?
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.
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.
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.
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.
My mistake ... my eye must have jumped a few posts ... it was your example I was referring to, right in this thread.
Doesn't Compile: Compiles: Finding this thread again reminded me that semi colons are partially to blame.
This also compile (w/o semi's in the declarations):
Now that's some fancy logic...
Hey, at least it compiles...
Paul