Last active
November 15, 2025 10:21
-
-
Save felias-fogg/8f4e1fdb3be14a598467842b03a3aef9 to your computer and use it in GitHub Desktop.
A small program leading to debugging problems when compiled with avr-gcc 7.3.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This program, when compiled with AVR-GCC 7.3.0, the standard version | |
| // for the Arduino AVR framework, will generate wrong debugging information. | |
| // When stopped just before the line buf[0] = ... and setting | |
| // num to 1001, then after two single-steps, num has become 1003 (which | |
| // is not true!), and after another singel-step it is back to 16000. | |
| // You can check that, e.g., by using simavr and avr-gdb. | |
| #include <string.h> | |
| #include <avr/pgmspace.h> | |
| char fun(int num) { | |
| static char buf[10]; | |
| buf[0] = '\0'; | |
| if (num == 0) { | |
| return buf[0]; | |
| } | |
| if (num >= 1000) { | |
| strcat_P(buf, PSTR("")); | |
| num = num % 1000; | |
| } | |
| return buf[num]; | |
| } | |
| int main() { | |
| return fun(16000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment