I often look at other peoples code and admire what appears to me to be an elegant solution for various tasks. I then try to incorporate some of these ideas. Ideas such as tight or cohesive functions, avoiding global variables, employing state machines, structured programing etc. So I try to keep these goals in mind, that is create efficient code that can be easily maintained by others. However, I do struggle and spend a lot of time deciding what is the best approach and suspect these are some of the things that separates a good programmer from the not so good. I am trying to implement a State Machine for sending UDP packets. I started with hastily thrown together example to use as a starting point. I tidied it up, added additional states, modified to support a passed-to-function (using ROM char) message to send rather than a hard coded message and added some debug. (A previous thread relates to debug). So now I have a state machine where I need to call the function 5 times with the same message to be sent to ensure the correct message is sent. Called at least 5 times in the hope that it transition thru all states to at least send msg. This is not elegant. So I question what is a good way to signal the UDP state machine that a message needs to be sent. Possible solution is to use a global variable that the state machine examines in the Nothing-to-do-State and then take a snap shot of the message to send once one appears in the buffer. But this means the message is no longer passed by ref to ROM but a reference to a global (RAM) string. I then must create a lock indicating to other processing that you can not change the message to send until the previous one has been sent, but I still need the state machine to execute periodically to ensure that it is services. I could use a return value from the UDP process that is true only when there UDP state machine idle, this seems elegant as it makes it easy to have the state machine execute periodically but creates an additional overhead. So I get bogged down step back and think ... What is required A mechanism to signal the UDP state machine that something is to be sent A mechanism to signal the caller that it is ok to send A mechanism to pass the message to send. A mechanism to ensure the state machine is called periodically. My best solution is to use a single global string that can provide for all the above mechanisms. But this results in a function the requires the use of a global variable, lacks cohesion, adds complexity to the caller as the caller must now copy the text to a global string before calling the function. To improve the code, I think to pass the string by reference but this seems to just add overhead as the same pointer will always be passed. i.e the location of memory used for all the mechanisms is fixed. So my final solution will be to use a single global string for everything and pass nothing and return nothing and include some macros to add another level of abstraction to make the code more readable. Is this the way you would do it. Any thoughts warmly welcome. Cheers justin --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .