Better code check before compile?


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    If you mean my example, OK, it is a not efficient one but I was trying to show that you can have many Returns from the same sub.

    Sure it can be made more compact or efficient, but still. Compiler has difficult time to check this for errors.

    Ioannis

  2. #2
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    Ok, here is an example (not exact syntax, just to get idea)

    Code:
    MAINCODE: 'do something
    high PORTC.0
    PAUSE 500
    low PORTC.0
    Pause 500
    GOSUB CHECKER
    GOTO MAINCODE
    CHECKER:
    TOGGLE PORTD.0
    RETURN
    In above example, if we remove RETURN, it will compile fine in PBP, but will produce unusable code. But even on ZX Spectrum, it would give us "Gosub without return" error, and save our time.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    Agreed. This is easy to check, but above we stated other cases that are difficult to check.

    So a sub-without-return check in whole is not easy to implement. I suppose... Maybe Charles knows better to justify it.

    Ioannis

  4. #4
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    There have been situations where if a test meets certain criteria you want to go through 5 sequences of code. However, if one of the criteria is missing, you want to skip the first sequence and do the other 4. On down the line, you may only need to do the last 2. The subroutine may look like;
    Code:
    Main:
    SELECT CASE Var
     CASE < 50 : GOSUB Sub1
     CASE < 100 : GOSUB Sub2
     CASE < 150 : GOSUB Sub3
     CASE < 200 : GOSUB Sub4
     CASE ELSE : GOSUB Sub5
    END SELECT
    GOTO Main
    
    Sub5:
     TOGGLE LED1
    Sub4:
     TOGGLE LED2
    Sub3:
     TOGGLE LED3
    Sub2:
     HIGH LATA.4
    Sub1:
     LATB = 0
    RETURN
    Here is a legitimate case of needing only 1 RETURN for multiple subroutines.

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    That is exactly what I have on my mind in post #8.
    Maybe it will be useful if compiler give just warning about missing RETUN.
    But That wouldn't prevent bad stuff from happening same as it throwing an error wouldn't prevent that. So no real point of having it.

  6. #6
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    Another "bug" found - you can easily refer to out of array bounds and it won't give any error during compile
    like

    MAS var byte[5]
    MAS[10]=20

    Won't give any error or warning.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    You may have found something you did not know and it IS something to be aware of but it's not a bug. It's like that by design.
    It's all covered in details thru out section 7.6 in the manual - read it ;-)

    /Henrik.

Similar Threads

  1. Code check and refinement suggestions?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 31st July 2013, 02:37
  2. Replies: 4
    Last Post: - 24th January 2007, 22:20
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  4. Can some one please check my code out thanks
    By Jhdgkss in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th February 2006, 08:19
  5. Code check (sorry)
    By barkerben in forum General
    Replies: 5
    Last Post: - 30th November 2004, 15:54

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts