Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Possible bug with endif / end if

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 412

newzealand.gif
PostPosted: Tue Apr 21, 2020 7:21 am    Post subject: Possible bug with endif / end if Reply with quote

I was looking at some code today, and noticed that one of my functions did not appear in the code explorer function list. Some testing revealed a typo in the 1st function, which did not cause a compile error. I'm not sure if there were any other problems. The code is several thousand lines long, but I wrote a short test program that demonstrates the issue.

This compiles OK, and both functions appear in the code explorer list.

Code:
$regfile = "m1284pdef.dat"
$crystal = 9830400
$framesize = 500
$hwstack = 500
$swstack = 500


dim x as byte
dim y as byte
dim z as byte


declare function testone() as string
declare function testtwo() as string



  do

       x = testone()
       y = testtwo()



  loop


  '*************************************************
  function testone() as string

      if z =1 then
        'do nothing

      end if

  end function

 '****************************************************
  function testtwo() as string
      if z= 2 then
        'do nothing

      end if

  end function


On the other hand, this typo does compile OK also, BUT the second function is now missing from the code explorer list. There are several output changes also which led me to finding the typo.

Code:

$regfile = "m1284pdef.dat"
$crystal = 9830400
$framesize = 500
$hwstack = 500
$swstack = 500


dim x as byte
dim y as byte
dim z as byte


declare function testone() as string
declare function testtwo() as string



  do

       x = testone()
       y = testtwo()



  loop


  '*************************************************
  function testone() as string

      if z =1 then
        'do nothing

      endif       'THIS IS THE TYPO THAT CAUSED THE ISSUE

  end function

 '****************************************************
  function testtwo() as string
      if z= 2 then
        'do nothing

      end if

  end function

 


(BASCOM-AVR version : 2.0.8.2 )

_________________
Neil
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5069
Location: Holland

blank.gif
PostPosted: Tue Apr 21, 2020 8:37 am    Post subject: Reply with quote

you best use the Code Explorer to check your code.

you probably did not read what was written about Code Explorer : it uses a different new parser to check code. it is independent of the compiler. (at the moment of writing).
the compiler is forgiving : it will assume things, but that is not convenient in all cases.
in case of endif it will change that during compiling into end if.

when you turn on 'format code' the 'endif' will be changed to 'end if' automatic.

your function return a string. the compiler will happy transform that to a byte you assign, but it is not really good practice.

_________________
Mark
Back to top
View user's profile Visit poster's website
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 412

newzealand.gif
PostPosted: Tue Apr 21, 2020 8:42 am    Post subject: Reply with quote

Thsnks Mark. Im not at work now; what hapoens to #endif ? I assume that remains unchanged?
_________________
Neil
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5069
Location: Holland

blank.gif
PostPosted: Tue Apr 21, 2020 9:02 am    Post subject: Reply with quote

#endif remains as it is. and is something totally different.
_________________
Mark
Back to top
View user's profile Visit poster's website
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 412

newzealand.gif
PostPosted: Wed Apr 22, 2020 11:14 pm    Post subject: Reply with quote

Thanks Mark. that has been a big help. I DID read the forum discussions on errors in code explorer but errors was turned off and I hadn't got into the habit of looking.
It has enabled me to find a number of error such as a couple of "exit sub" inside a function, and declaring a string var in a function decl, then using a byte var inside the function !!.
These were not picked up by the assembler.
However I have one error in code explorer which has me beat, and I attach the relevant code here:
Code:


 '*******************************************************************************
$regfile = "m1284pdef.dat"                            
$crystal = 9830400                                          
$framesize = 800                                          
$hwstack = 550                                              '
$swstack = 550
$frameprotect = 1
config submode = old                                      
$include "config_mmcsd_hc.bas"                              
$include "config_AVR-DOS.BAS"
$PROG &HFF , &HC7 , &HD0 , &HFD
 '==============================================================================

Declare Function Cleanupstring(byval Sourcestring As String) As String
Declare Function Davis_wind_direction() As String
Declare Function Davis_wind_speed() As String
declare function find_bootloader() as string
Declare Function Get_rssi() As String
Declare Function Getmeterresponse(byval metercommandstr As String) As String
declare function mic_check() as string
Declare Function Mypi_battery_soc() As Single
Declare Function Noise_profile(byval Parameterstr As String) As String      
Declare Function pi_response(byval picommandstr As string) As string    '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Code explorer doesnt like this
declare Function quick_sd_card_check() As Byte
Declare Function Send_http_head(byval Serveraddr As String) As String
Declare function TCP_connect(byval Myserver As String * 50 , byval Myport As Integer) as byte
declare function verify_SLMtime(byval slmtime as string) as string
Declare Function Verify_time(byval Responsestr As String) As String
Declare function Waitfortelitresponses_sec(byval Respstr As String * 30 , byval Resptimeoutb As Byte) as byte
Declare Function Waituntil(byval Respstr1 As String , byval Respstr2 As String , byval Abortstr As String , byval Resptimeoutb As Byte) As String
Declare Function Whoru() As String
Declare Sub Append_dummynoise()
Declare Function Cleanupstring(byval Sourcestring As String) As String
Declare Function Davis_wind_direction() As String
Declare Function Davis_wind_speed() As String
declare function find_bootloader() as string
Declare Function Get_rssi() As String
Declare Function Getmeterresponse(byval metercommandstr As String) As String
declare function mic_check() as string
Declare Function Mypi_battery_soc() As Single
Declare Function Noise_profile(byval Parameterstr As String) As String
Declare Function pi_response(byval picommandstr As string) As string
declare Function quick_sd_card_check() As Byte
Declare Function Send_http_head(byval Serveraddr As String) As String
Declare function TCP_connect(byval Myserver As String * 50 , byval Myport As Integer) as byte
declare function verify_SLMtime(byval slmtime as string) as string
Declare Function Verify_time(byval Responsestr As String) As String
Declare function Waitfortelitresponses_sec(byval Respstr As String * 30 , byval Resptimeoutb As Byte) as byte
Declare Function Waituntil(byval Respstr1 As String , byval Respstr2 As String , byval Abortstr As String , byval Resptimeoutb As Byte) As String
Declare Function Whoru() As String
Declare Sub Append_dummynoise()

 '*****************************************************

Function pi_response(picommandstr As String) As String

      Local Q As Byte                                       'number of char received
      Local Tempstr7 As String * 100
      Local Td As Long

  #if Pi_fitted = 1
'(
      This function runs a command and returns the response to the caller

      *******  VALID PI COMMANDS   *********
      upload,1   pi free to send audio files to the server
      upload,0  inhibit uploads to server
      status?    get status. bloody slow response from pi
      shutdown  tell pi to shutdown in an orderly manner. takes 30s
      pitakeboth    take camera image + audio recording    
      ssh,0
      ssh,1
      ppp,0  
      ppp,1
      startrecord,xx   start a recording xx seconds long
      stoprecord
      bitrate,nn   nn = 8,12,16,24,
      register,phonenumber     in format  "%2b64275404773"
      Philips terminators:
      after all echos  $$ <CR>
      after all data ##   <CR>

      ')


      Tempstr7 = ""

      Td = Local_secl + 10                                  '10 secs

      If picommandstr <> "" Then
         Print #7 , picommandstr                            'send cmd to pi ser port


         Do

            Rxbyte = Inkey(#8)                              '#8 is pi sw uart ser port
            If Rxbyte <> 0 Then
               Tempstr7 = Tempstr7 + Chr(rxbyte)
            End If

         Loop Until rxbyte = 35 or Local_secl >= Td         ' 35 = #  expected terminator

         Delchars Tempstr7 , 32                              'remove spaces

         If Tempstr7 <> "" Then
            Print #1 , ">> Pi said:" ; Tempstr7
         Else
            Print #1 , ">> no response from pi"
            Tempstr7 = "no response from pi"
         End If


         pi_response = Tempstr7                              'return the response
      end if

  #endif

End Function


 '******************************************************
 


The code explorer complains about the declaration arrowed, and says "parameter not same as declared .... line 382 posn 30." This is the ONLY error that code explorer finds, and the program compiles and runs correctly. There are 15 other functions all with the same pi_ prefix to the name, but changing the name (or the parameter) to something else doesn't remove the error./quote]

_________________
Neil
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1827

blank.gif
PostPosted: Thu Apr 23, 2020 6:37 am    Post subject: Reply with quote

What happens if the byval is added to the function itself?
Back to top
View user's profile
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 412

newzealand.gif
PostPosted: Thu Apr 23, 2020 7:37 am    Post subject: Reply with quote

ahhhhhh that made the problem go away. If I could, I'd buy you a beer. Thanks MWS.
_________________
Neil
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1827

blank.gif
PostPosted: Fri Apr 24, 2020 12:45 am    Post subject: Reply with quote

That would be a far traveling beer Very Happy
But thanks for the offer.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum