Page 1 of 1

Back end error - 'else' without a previous 'if'

Posted: 07 October 2011, 17:49 PM
by Don_Kirby
Compiling under v3.3 for a ZX24n, I get a back end build error:
Compiler wrote: HoverGauge.c: In function 'zf_Main':
HoverGauge.c:176: error: 'else' without a previous 'if'
make: *** [HoverGauge.o] Error 1
make: Leaving directory `S:/ZBasic Code/zxTempDir/Hover'
Error: one or more errors occurred in the back-end build process for "Hover.zxb"
Which corrolates to the last else statement in the following C code:

Code: Select all

zf_Main(void)
{
	mzf_RunOnce();
	while (1)
	{
		for &#40;mzv_n = 1; mzv_n <= 6; mzv_n++&#41;
		&#123;
			if &#40;&#40;int16_t&#41;progMemReadWord&#40;PROG_MEM&#40;&#40;uint8_t *&#41;&zv_Alarm + &#40;&#40;uint16_t&#41;mzv_n * 2&#41; + 65534&#41;&#41; <= zv_Temp&#91;mzv_n - 1&#93;&#41;
			&#123;
				mzf_CharliePlex&#40;2 * mzv_n&#41;;
				persistWriteByte&#40;&zv_Mode, mzv_n&#41;;
				zv_AlarmCondition = ZX_TRUE;
			&#125;
			else if &#40;persistReadByte&#40;&zv_Mode&#41; == mzv_n&#41;
			&#123;
				mzf_CharliePlex&#40;&#40;2 * mzv_n&#41; - 1&#41;;
				zv_AlarmCondition = ZX_FALSE;
			&#125;
			else
			&#123;
				mzf_CharliePlex&#40;mzv_n - mzv_n&#41;;
				zv_AlarmCondition = ZX_FALSE;
			&#125;
		&#125;
		&#123;
			uint8_t _zv_selectValTemp07;

			_zv_selectValTemp07 = persistReadByte&#40;&zv_Mode&#41;;
			else
			&#123;
				persistWriteByte&#40;&zv_Mode, 1&#41;;
			&#125;
		&#125;
	&#125;
&#125;
Which is the following in ZBasic:

Code: Select all

Public Sub Main&#40;&#41;
	Call RunOnce&#40;&#41;
	
	Do
		For n = 1 to MaxMode
			If Alarm&#40;n&#41; <= Temp&#40;n&#41; Then 'I think this is wrong...
				Call CharliePlex&#40;n*2&#41; 'Turn on one of the red LED's
				Mode = n 'and display the value
				AlarmCondition = True 'Set the alarm flag
			ElseIf Mode = n Then
				Call CharliePlex&#40;n*2-1&#41; 'turn on one of the green LED's
				AlarmCondition = False 'clear the alarm flag
			Else
				Call CharliePlex&#40;n-n&#41; 'Turn them off
				AlarmCondition = False 'clear the alarm flag
			End If
		Next n
		
		Select Case Mode
			#IfDef TempInstalled
			Case 1 to 4 'tempuratures
				Call UpdateDisplay&#40;Temp&#40;Mode&#41;, PauseDisplay&#41;
				#IfDef GPSEnabled
					Call RememberSpeed&#40;&#41;
				#EndIf
				#IfDef DebugEnable
					Debug.Print&#40;Temp&#40;Mode&#41;&#41;
					Call Sleep&#40;0.1&#41;
				#EndIf
			#EndIf
			
			#IfDef GPSInstalled
				Case 5 'GPS Speed
					Call UpdateDisplay&#40;GetSpeed&#40;&#41;, PauseDisplay&#41;
					Call RememberSpeed&#40;&#41;
					#IfDef DebugEnable
						Debug.Print&#40;GetSpeed&#40;&#41;&#41;
						Call Sleep&#40;0.1&#41;
					#EndIf
				Case 6 'GPS Course
					Call UpdateDisplay&#40;GetCourse&#40;&#41;, PauseDisplay&#41;
					Call RememberSpeed&#40;&#41;
					#IfDef DebugEnable
						Debug.Print&#40;GetCourse&#40;&#41;&#41;
						Call Sleep&#40;0.1&#41;
					#EndIf
			#EndIf
			Case Else
				Mode = 1
		End Select
	Loop
End Sub

You'll notice that the conditional compilation directive doesn't encapsulate the 'Case Else'. In this particular instance, none of the conditional code is being used, leaving a Select Case with only the Case Else. While I understand what's happening here, I wonder if there's another way to for the compiler to handle the error before it get's to the back end.

As an aside, the IDE highlights the corrosponding line number of ZBasic code, in this case 176, when in actuality it is referring to the C code line 176. Perhaps this could be changed to point to the last line in the module, to indicate that the error is outside the realm of that module?

-DK