Don't use both. What was printed in the above post will GOTO a new address, then erase the RETURN address. This will generate a Stack Underflow condition and the PIC will "exhibit unpredictable behavior". Just use GOTO and leave the Stack alone.
Don't use both. What was printed in the above post will GOTO a new address, then erase the RETURN address. This will generate a Stack Underflow condition and the PIC will "exhibit unpredictable behavior". Just use GOTO and leave the Stack alone.
But if I understand correctly he want to goto and never return.
So you need to pop stack to prevent overflow.
Then yes, POP the Stack. Not sure when such an approach might be considered good programming practice, though.
using goto to control program flow = spaghetti code [hard to unravel ,hard to modify ]Not sure when such an approach might be considered good programming practice
spaghetti code with stack popping to undo dead subs ?
franken code ? [as in Frankenstein ]
you would need good comments with a flow diagram and a state diagram at hand to unravel it
Warning I'm not a teacher
Not necessarlly, Lot of hi level programing language have this already implemented. eg in .net: On Error GoTo, Try, catch, etc...
Same could be done for HW. If something external happened then you need unconditionally goto something, and start program from known place.
It is not easy to implement, by any means. But it could very useful.
What longpole001 have exactly on his mind, I can't tell...
You could count your gosub nesting level in another variable.
Increment for every gosub, and decrement for every return.
You don’t know about PBP's own gosubs, but they are supposed to be the compiler’s problem, and aren’t your responsibility.
So you would know if the value wasn’t zero when you thought it should be.
When compiler gosub, it will always return. Unless you use ISR to modify stack, which I wouldn't recommend.
hmm, in python at least a sub with a "try" still returns , even if the processing aborts and executes an "try" error routine.
i see no goto or stack popping going on.
a couple of python subs with try
Code:def process_d(tname,q): while exitflg==0: dx=ser.readline() try : rt='s' ff= string.rstrip(dx) int(ff,16) ##non hex chr will cause ValueError if dx[0]=='A': rt='w' #print dx ts=str(datetime.datetime.now())[:19] r_x=[ts,dx,rt] queueLock.acquire() q.put(r_x) queueLock.release() except ValueError: #print dx dx=[] def bag_reading (): global readings bag_data_time =datetime.datetime.now() if len(readings)>0: try: conn=sqlite3.connect('/media/CORSAIR/wh2.db') curs=conn.cursor() curs.executemany("INSERT INTO log values((?),(?),(?),(?))", (readings)) # commit the changes conn.commit() conn.close() print 'write ',len(readings),' ',readings[-1][0] readings=[] bag_data_time += datetime.timedelta(minutes=5) except sqlite3.OperationalError as err : print 'db busy',err bag_data_time += datetime.timedelta(minutes=1) return bag_data_time
Warning I'm not a teacher
Bookmarks