Timeline for What happens if there is a runtime error?
Current License: CC BY-SA 3.0
29 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 13, 2017 at 12:50 | history | edited | CommunityBot |
replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
|
|
| Dec 3, 2016 at 17:13 | comment | added | Edgar Bonet | Your statement about the program restarting when calling a NULL function pointer was correct, at least on the AVR. I was just pointing out that restarting the program is not quite the same as a reset. BTW, there is no illegal instruction involved in the process. “Would you please check it out?” I cannot find anything wrong in your answer. | |
| Dec 3, 2016 at 15:47 | comment | added | Ricardo | @EdgarBonet - Thanks for pointing out the problem with my answer. I read the link you provided and have tried to correct the statements about local variables. Would you please check it out? Thanks! | |
| Dec 3, 2016 at 15:46 | history | edited | Ricardo | CC BY-SA 3.0 |
Corrected statements about uninitialized local variables as per Edgar Bonet's comments.
|
| Dec 3, 2016 at 12:37 | comment | added | Connor Wolf | @EdgarBonet - Point taken. Too bad I can't edit my older comments. | |
| Dec 3, 2016 at 12:22 | comment | added | Edgar Bonet | @Connor Wolf: You wrote: “the SRAM is initialized to 0 at reset or startup”. This is incorrect. Unlike the IO registers, the SRAM is not initialized by the hardware at startup. The BSS section of the RAM (and only this section) is initialized to zero by the C runtime. The DATA section is initialized to whatever contents the programmer requested. All the remaining RAM is left uninitialized. | |
| Dec 3, 2016 at 12:16 | comment | added | Edgar Bonet |
You wrote: “array[-100] = 10; [...] you only messed up with RAM [...] thus your program is safe.” You may well end up writing into the IO space of the MCU, which is memory-mapped right below the RAM on the AVRs. This is definitely not safe. “[Calling a NULL function pointer] that's equivalent to a soft boot”. Not exactly. The program will restart from the very beginning: it will initialize the stack pointer, the RAM, call main, etc. But, unlike a soft boot, this does not reset the IO registers to their default initial state.
|
|
| Dec 2, 2016 at 23:10 | comment | added | per1234 |
the C++ compiler does that for you. It sets it as zero Local variables are not initialized. I interpret status to be local in your example therefore this is wrong. it's not considered good practice to rely on that behaviour it actually is considered good practice to rely on that behavior for global variables since it's guaranteed that they will be zero-initialized and zero initializing globals in your code can waste memory(though current compilers should be smart enough to avoid this) see atmel.com/webdoc/AVRLibcReferenceManual/FAQ_1faq_varinit.html
|
|
| Mar 27, 2014 at 3:30 | comment | added | Ricardo | @ConnorWolf Right! Well spotted. Just edited and fixed my answer. | |
| Mar 27, 2014 at 3:29 | history | edited | Ricardo | CC BY-SA 3.0 |
Fixed conceptual problem as pointed out by Connor Wolf.
|
| Mar 27, 2014 at 3:14 | comment | added | Connor Wolf |
One note: The good news is that you only messed up with RAM and not with the EEPROM, thus your program is safe.. The program running on the ATmega is stored in the Flash memory, not EEPROM. The EEPROM is generally only 1-2 KB, and is more for storing small amounts of non-volatile data (think: user configuration settings, serial number, etc...), not actual code.
|
|
| Mar 11, 2014 at 2:05 | review | Suggested edits | |||
| Mar 11, 2014 at 2:22 | |||||
| Feb 25, 2014 at 11:41 | history | edited | Ricardo | CC BY-SA 3.0 |
Removed reference to uninitialized variables as per Fake Name comments.
|
| Feb 24, 2014 at 11:19 | comment | added | Ricardo | @FakeName - BTW, that picture always reminds me of the great Cat Yodeling technique from Engineer's Guide to Cats at 4:57min. | |
| Feb 24, 2014 at 11:14 | comment | added | Ricardo | @FakeName - Right! I'll edit my answer to fix the statement about uninitialized variables. As for the other great suggestions you posted, why don't you make them an answer and I'll add a reference to it from mine? Glad to see you (or maybe just the picture of your annoyed cat) around here. | |
| Feb 24, 2014 at 4:58 | comment | added | Connor Wolf | Also relevant is the question about recursion: arduino.stackexchange.com/questions/355/… since recursion is one of the easy ways to blow the stack. | |
| Feb 24, 2014 at 4:44 | comment | added | Connor Wolf | There is an interesting example of what happens when you run out of SRAM here: electronics.stackexchange.com/questions/42049/…. Basically, the stack clobbers part of the heap, or vice versa. This can do interesting things like corrupt some part of the stack-frame (breaking function returns, etc), or writing invalid data to variables. | |
| Feb 24, 2014 at 4:39 | comment | added | Connor Wolf | Furthermore, the SRAM is initialized to 0 at reset or startup, so you can make some informed guesses about uninitialized variables, if you want to live dangerously. You shouldn't rely on this behaviour, but it is interesting. | |
| Feb 24, 2014 at 4:38 | comment | added | Connor Wolf | @Ricardo - One comment I would make is that non-explicitly initialized variables are not necessarily uninitialized. Variables defined outside of functions generally have what's termed "automatic storage duration", which then get default-initialized to zero. See en.cppreference.com/w/cpp/language/default_initialization for more information. The initialization behaviour is complex enough that it's probably dangerous to rely upon, but making blanket statements is probably not a great idea. | |
| Feb 24, 2014 at 4:32 | comment | added | Connor Wolf | @AnnonomusPerson - The only likely mechanism for damage would be code that changes pin state in a manner that results in a bus contention (e.g. the ATmega trying to set a pin high, while external hardware is setting it low). It's also possible that if there is external hardware the ATmega is controlling that cannot handle certain control-input states, the external hardware could cause some manner of failure and damange, but an arduino with nothing connected it pretty bulletproof. The arduinos have series resistors to prevent possible contention issues on the serial lines. | |
| Feb 17, 2014 at 15:21 | comment | added | Anonymous Penguin | Would any of this damage the Arduino? | |
| Feb 15, 2014 at 12:47 | history | edited | Ricardo | CC BY-SA 3.0 |
Tested what happens if you call a null function pointer and reported it here.
|
| Feb 15, 2014 at 2:11 | history | edited | asheeshr | CC BY-SA 3.0 |
Typos; factual correction
|
| Feb 14, 2014 at 22:29 | comment | added | Ricardo | Thanks!! I think we should strive to give great answers as much as possible. But it worries me a little the fact that we don't have that many REAL EE EXPERTS that could look at answers like mine and find any glaring mistakes. Actually, that's the reason I posted the answer even though I don't know that much about AVR MCUs. That's to see if we get someone to correct it. We sure don't want smart pents like me saying stuff that isn't right and getting away with it. But that's probably a discussion for the Meta site. | |
| Feb 14, 2014 at 22:24 | comment | added | The Guy with The Hat | Great! The best answer I have seen on Arduino.SE so far! | |
| Feb 14, 2014 at 22:20 | history | edited | Ricardo | CC BY-SA 3.0 |
Added answers more clearly.
|
| Feb 14, 2014 at 22:18 | vote | accept | The Guy with The Hat | ||
| Feb 14, 2014 at 22:12 | history | edited | Ricardo | CC BY-SA 3.0 |
Added answers more clearly.
|
| Feb 14, 2014 at 21:24 | history | answered | Ricardo | CC BY-SA 3.0 |