Demonstrate what can happen when array limits are exceeded.
Fork of SimpleConsoleTest by
Diff: main.cpp
- Revision:
- 2:80464803bc2f
- Parent:
- 1:a000e0121191
diff -r a000e0121191 -r 80464803bc2f main.cpp --- a/main.cpp Thu Oct 12 19:57:14 2017 +0000 +++ b/main.cpp Thu Oct 12 20:35:08 2017 +0000 @@ -3,23 +3,25 @@ File: main.cpp Project: ArrayLimits -//------------------------------------ -// Tera Term configurations -// Terminal - New-line, Receive LF, Transmit LF -// Serial port - Data 8 bit, Parity none, Stop 1 bit data, Flow control none. -// Baud as specified below. -//------------------------------------ - -// Serial pc(SERIAL_TX, SERIAL_RX, 921600); // Highest Tera Term speed - works. -// Serial pc(USBTX, USBRX, 115200); // Highest common speed - works. -// Serial pc(USBTX, USBRX); // Default 9600 baud, alternate pin names - works. + Demonstrates abuse of array limits on Nucleo boards. + + If necessary, avoid this with code like: + + if (index > SIZE - 1) { + index = SIZE - 1; + } else if (index < 0) { + index = 0; + } + Use index... + + Created by Dr. C. S. Tritt; Last revised 10/12/17 (v. 1.0) */ #include "mbed.h" int main() { float a[] {1.0, 3.0, 5.0, 7.0, 9.0 }; - printf("Hello World !\n"); + printf("Hello World !\n\n"); for (int i = 0; i > -10; i--) { // Displays zeros and one NaN. printf("a[%d] is %f.\n", i, a[i]);