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,172


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    Added to the above, no one can guarantee you that the software will always run, even with faults in it. MCU's can stop anytime and hardware must protect itself in that case.

    Now, regarding Subs, it is not easy or feasible at all, to check for correct pairs of gosub-return. It is not the same as open-close of { and } in C for example.

    In the case of Returns, you can have one or 100 for the same sub. So, how will the compiler check?

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    it is simple. Just count number of Subroutines and RETURNs and make sure they match, that's all, and already done 30 years ago.

    Regarding what happened - it was huge (about 30 meters) Christmas tree 8 channel light controller. The code enables lights at max power for 0.1 second, to give "blink" effect. It worked for 2 years without any issues, until now, when I added some new programs, and forgot to add RETURN, so lights remain at high power for about 10 minutes, instead of 0.5second. It ended up with 9 pieces of solid state relays fried, until thermal switch cut off the power
    Last edited by CuriousOne; - 26th December 2019 at 15:33.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,158


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    Even more simple.

    Just add different label for subroutines, say, subroutines should start with SUB statement, after the label. At compile time, do check and that's all.

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    Then 80% of my programs wouldn't compile. I often use multiple entry point in same sub. And have only one return at end.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    Or the reverse. Have one entry and multiple exits:

    Code:
    gosub test
    
    ....
    
    test:
    if x=1 then
       a=1
       return
    endif
    
    if x=2 then
       a=2
       return
    endif
    
    return
    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    So you're doing it wrong - same for overlapping for-next cycles

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    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

Similar Threads

  1. Code check and refinement suggestions?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 31st July 2013, 03:37
  2. Replies: 4
    Last Post: - 24th January 2007, 23:20
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 23: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, 09:19
  5. Code check (sorry)
    By barkerben in forum General
    Replies: 5
    Last Post: - 30th November 2004, 16:54

Members who have read this thread : 0

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