Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Possible compiler error - Do Until statement

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
cloxwerx



Joined: 01 Dec 2005
Posts: 37
Location: Tucson, Arizona

Posted: 01 December 2005, 18:09 PM    Post subject: Possible compiler error - Do Until statement Reply with quote

Working with a BX-24 program and converting to ZX-24 I find the following strange behavior:
Temperature is a fixed two column array. Lookup is within the table range.
This works on the BX and not on the ZX (never breaks out when Lookup is Greater):

Do Until (Lookup > TEMPERATURE(1,kk)) 'Find first entry which is less than Lookup millivolts
kk = kk+1 'Point to next entry
Loop

When I add an IF to the ZX version the code works as it should have with just the Do Until:

Do Until (Lookup > TEMPERATURE(1,kk)) 'Find first entry which is less than Lookup millivolts
If (Lookup > TEMPERATURE(1,kk)) Then
EXIT Do
End IF

kk = kk+1 'Point to next entry
Loop

Compiler error or programmer error?

Thanks,
Dennis
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 01 December 2005, 18:41 PM    Post subject: Reply with quote

To help isolate the problem, try turning off the compiler optimization. Put this at the top of your PJT file:
Code:
--optimize=no-optimize
Mike
Back to top
cloxwerx



Joined: 01 Dec 2005
Posts: 37
Location: Tucson, Arizona

Posted: 01 December 2005, 20:39 PM    Post subject: Reply with quote

Thanks, Mike. That allowed the Do Until to function and the program proceeded to another impasse that I feel is a compiler error as well. Here's a code snippet:

Do Until (Lookup > TEMPERATURE(1,kk)) 'Find first entry which is less than Lookup millivolts
' If (Lookup > TEMPERATURE(1,kk)) Then
' EXIT Do
' End IF

kk = kk+1 'Point to next entry
' Call PutQueueStr(DisOutQue," " & Fmt(CSng(Lookup),0) &" " & Fmt(CSng(Temperature(1,kk)),0))
' Call Delay(1.0)
Loop
Call Delay(1.0)
Call PutQueueStr(DisOutQue," P")

' Temp=CSng((Lookup-TEMPERATURE(1,kk)))/CSng(TEMPERATURE(1,kk-1)-TEMPERATURE(1,kk))* _
' CSng(TEMPERATURE(2,kk-1)-TEMPERATURE(2,kk))+CSng(TEMPERATURE(2,kk))
Call PutQueueStr(DisOutQue," " & "Pre TEMPString")
Temp=71.4
TempString = "T=" & CStr(CInt(Temp)) 'Convert temperature to characters

I've commented out some of the debugging prints and a computation so very little remains for the compiler. When the loop falls through to the next PutQueStr I get a spurious character printed and nothing more which suggests the program is hung. The next PutQueStr doesn't happen. RAM used is less than 50 bytes, so stack problems should be out.

Thanks for your advice so far. And I thought I was going to try out my 1500 line BasicX program after testing this simple one. Looks like I should have been a beta tester. OOps, maybe I am Very Happy

Dennis
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 01 December 2005, 21:19 PM    Post subject: Reply with quote

I have confirmed the optimization error and a solution is being tested.

I have not yet been able to replicate the second problem. I attempted to construct a compilable program using the data that you provided but I apparently missed something because it works as expected. Of course, I had to make some assumptions about the parts that aren't shown. Here is what I tried:
Code:

Dim ba(1 to 10) as Byte
Dim oq(1 to 40) as Byte

Sub Main()
   Dim i as Integer

   Call OpenQueue(oq, SizeOf(Oq))
   Call OpenCom(1, 19200, 0, oq)

   for i = 1 to UBound(ba)
      ba(i) = CByte(UBound(ba) - i + 1)
   Next i

   Call bar(4)
   Call PutQueueStr(oq, "done")
End Sub

Sub bar(ByVal v as Byte)
   Dim TempString as String
   Dim Temp as Single
   Dim i as Integer

   i = 1
   Do Until (v > ba(i))
      i = i + 1
   Loop
   Call Delay(1.0)
   Call PutQueueStr(oq," P")
   Call PutQueueStr(oq," " & "Pre TEMPString")
   Temp=71.4
   TempString = "T=" & CStr(CInt(Temp))
End Sub


The output generated:
Code:
 P Pre TEMPStringdone


I also tested this with ba being defined as shown below and used a constant value for the first index. The result was the same.
Code:
Dim ba(1 to 2, 1 to 10)
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 01 December 2005, 21:33 PM    Post subject: Reply with quote

As a point of order, it might be better to start a new problem in a new thread.

My immediate thought is that your queue is full. I didn't see the consumer code that takes data off the queue. However I"m assuming this code runs under BasicX so it might be something different. Again the trick as you have been doing is to isolate the problem to a small amount of code.

Mike
Back to top
cloxwerx



Joined: 01 Dec 2005
Posts: 37
Location: Tucson, Arizona

Posted: 01 December 2005, 21:53 PM    Post subject: Reply with quote

Thanks, Don and Mike. I'll pare the code down and see if I can get it to a smaller defined problem. I'll start a new thread with that.

Dennis
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group