Palermo
Offline
Full Member
Karma: 0
Posts: 154
|
 |
« on: January 24, 2013, 03:22:28 pm » |
I don't get it, please help me out with this. What does actually abort() do in Arduino? I don't find any related documentation. If I upload this code into Arduino: void setup() { Serial.begin(19200); Serial.println("Start"); } void loop() { Serial.println("Start Loop"); abort(); }> I only get two dashes on the serial monitor, no "Start Loop" and even no "Start". It looks like not even setup() is running. Well, actually that's impossible, since something is "moving" on the serial line after all. What am I missing?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #1 on: January 24, 2013, 03:29:14 pm » |
What does actually abort() do in Arduino? It clearly has undesirable side-effects. Why would you want to use it?
|
|
|
|
« Last Edit: January 24, 2013, 03:35:39 pm by Coding Badly »
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35591
Seattle, WA USA
|
 |
« Reply #2 on: January 24, 2013, 03:30:07 pm » |
I only get two dashes on the serial monitor, no "Start Loop" and even no "Start". It looks like not even setup() is running. Well, actually that's impossible, since something is "moving" on the serial line after all. setup() is running, and buffering serial data. Then, loop() starts and buffers some more. Before anything can get shifted out, you call abort(), which does what it's name suggests. It stops the program that is running, including interrupts (which are how the serial data gets shifted out). So, the question is why are you calling abort()?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Palermo
Offline
Full Member
Karma: 0
Posts: 154
|
 |
« Reply #4 on: January 24, 2013, 03:33:28 pm » |
Btw, I was going to use abort() as a measure for halting the software in case totally unacceptable data were used as input. I understand that's somehow drastic as an error handling method. I wonder how/if/when abort() maybe used such as that.
I'm not going to write some crazy complex error handling routine for this particular purpose anyway, enough being to simply stop everything.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #5 on: January 24, 2013, 03:35:06 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
Palermo
Offline
Full Member
Karma: 0
Posts: 154
|
 |
« Reply #6 on: January 24, 2013, 03:35:06 pm » |
It clearly has undesirable side-effects. Why would want to use it?
I understand you care for others ... that's nice :-)
|
|
|
|
|
Logged
|
|
|
|
|
Palermo
Offline
Full Member
Karma: 0
Posts: 154
|
 |
« Reply #7 on: January 24, 2013, 03:36:38 pm » |
I see now!!! I've found it in stdlib.h :-) Thank you anyway, I appreciate that. It's nice to know there's people like you out there :-)
|
|
|
|
|
Logged
|
|
|
|
|
Palermo
Offline
Full Member
Karma: 0
Posts: 154
|
 |
« Reply #8 on: January 24, 2013, 03:38:11 pm » |
setup() is running, and buffering serial data. Then, loop() starts and buffers some more. Before anything can get shifted out, you call abort(), which does what it's name suggests. It stops the program that is running, including interrupts (which are how the serial data gets shifted out).
That was quite precise and complete. Respect!
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35591
Seattle, WA USA
|
 |
« Reply #9 on: January 24, 2013, 03:46:28 pm » |
I'm not going to write some crazy complex error handling routine for this particular purpose anyway, enough being to simply stop everything. In CATIA, we have, occasionally, dialog boxes that pop up that say "Click OK to terminate", like someone would really want to. The cause is almost always a result of failing to handle an exception. That sounds like what you are planning to implement. I would strongly encourage you not to do that. Restarting the Arduino because of a type, or noise on the serial line, or some other strange input arriving is not a best practice. It's far better to simply ignore out-of-range data.
|
|
|
|
|
Logged
|
|
|
|
|
Palermo
Offline
Full Member
Karma: 0
Posts: 154
|
 |
« Reply #10 on: January 24, 2013, 04:00:54 pm » |
I'm not going to write some crazy complex error handling routine for this particular purpose anyway, enough being to simply stop everything. In CATIA, we have, occasionally, dialog boxes that pop up that say "Click OK to terminate", like someone would really want to. The cause is almost always a result of failing to handle an exception. That sounds like what you are planning to implement. I would strongly encourage you not to do that. Restarting the Arduino because of a type, or noise on the serial line, or some other strange input arriving is not a best practice. It's far better to simply ignore out-of-range data. I completely agree with you, andI usually tend to spend quite some time on error handling. Especially because I'm not a professional programmer, so I'm going to use the code for myself, not for customers ;-) In this case I'm going to use abort() in a preliminary stage of the coding. I'm not going to bother much about providing valid alternative default values in case the input is going to be unacceptable. It's ok to me if it runs an infinite loop. It doesn't break anything at the moment. But it's good to know what it does precisely :-)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #11 on: January 24, 2013, 04:21:06 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
Palermo
Offline
Full Member
Karma: 0
Posts: 154
|
 |
« Reply #12 on: January 24, 2013, 05:35:45 pm » |
It could ... but I don't have the slightest idea of how to direct stderr to the serial ... so why bother adding this layer of complexity? No, seriously, how may I define __ASSERT_USE_STDERR ? Do I get to redirect it to the serial channel? How? Anyway, I find usefull that I can disable the assert() when I'm finished debugging, by simply defining NDEBUG once and for all. That's cool to know :-)
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6406
-
|
 |
« Reply #13 on: January 24, 2013, 06:45:33 pm » |
In this case I'm going to use abort() in a preliminary stage of the coding.
It's already been explained to you that calling abort() under any circumstances in an Arduino sketch is a bad idea. If you want the sketch to chop itself off at the ankles, you could use the while(1); that Coding Badly showed you. Personally I think doing that just because of duff input is probably a cop-out, but if you can't be bothered to do anything more user-friendly then it's a legitimate way to halt your sketch. Calling abort() is not.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #14 on: January 24, 2013, 06:47:31 pm » |
...but I don't have the slightest idea of how to direct stderr to the serial... If you do nothing special... #include <assert.h>
void setup( void ) { assert( false ); }
void loop( void ) { }
abort is called if the assertion fails. stderr does not come into the picture.
|
|
|
|
|
Logged
|
|
|
|
|
|