undefined states

just a quick question,

How do you design your code to prevent it slipping into an undefined state, i thought all that was needed was to create a default to first state in case the program slips outside the defined area.

Any help would be greatly appreciated

Reply to
jpmcg
Loading thread data ...

We need more context to give a useful answer. In general, stay within the defined areas of your programming language, tools, and target hardware.

Thad

Reply to
Thad Smith

Writing a program to default to a given state when things go wrong is like building a road with guardrails on corners -- it keeps you from getting into deeper trouble, but it doesn't prevent the original screw-up. Careful coding, or using language constructs that don't allow an illegal state to be assigned, are the only things that will keep things from screwing up in the first place.

I suggest you follow up this or Mr. Smith's post with a post that tells what you're trying to do and what's screwing up. It's most likely that you're either explicitly writing the wrong value to your state someplace, or that you've got a pointer wrong and you're writing some perfectly valid piece of data to a horribly wrong spot.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
Reply to
Tim Wescott

Undefined states are to be avoided at almost all cost. This would result in a non-deterministic behaviour. Therefore : statemachines have to define all states. Overflows in addition/subtraction and multiplications have to be trapped or avoided. A division by zero has also to be trapped or avoided. In the embedded world, there is command.com that takes charge - usually. The watchdog shall be quiet.

Rene

Reply to
Rene Tschaggelar

Defensive programming is a must!!!!!!!!!!

gm

Reply to
GMM50

Use a well defined state machine.

The following article might help:

formatting link

Deepa

--

formatting link
EventStudio 2.5 - Embedded System Modeling with Sequence Diagrams

Reply to
EventHelix.com

Just what is 'slipping' in this context?

In any case:

In general, you can't design software that can detect it's own malfunction. Search for "halting problem" on the 'net.

The best you can do is a "watchdog timer" or some other hardware to monitor the software operation.

If the problem is due to programmer error then you can minimize it by hiring experienced programmers and system testers.

??????????????

--
Nicholas O. Lindan, Cleveland, Ohio
Consulting Engineer:  Electronics; Informatics; Photonics.
Remove spaces etc. to reply: n o lindan at net com dot com
psst.. want to buy an f-stop timer? nolindan.com/da/fstop/
Reply to
Nicholas O. Lindan

Never thought about it. A finite state machine is often a machine that's trivial to code for, where some code contains thousands or millions of states, and the correctness of all combinations of states is not an interesting question, or even humanly possible to analyze.

One state might be a system call failure that is not accounted for, and the code crashes or malfunctions. The obvious prevention for such is to check the success and not assume. The pitfall here was a branch, not in the algorithm, but in the machine, that was not recognized as such.

Reply to
Bryan Hackney

as other people have said, watchdogs are OK

formatting link
and
formatting link

martin

Serious error. All shortcuts have disappeared. Screen. Mind. Both are blank.

Reply to
martin griffith

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.