Demonstrate what can happen when array limits are exceeded.

Dependencies:   mbed

Fork of SimpleConsoleTest by Charles Tritt

Committer:
CSTritt
Date:
Thu Oct 12 19:57:14 2017 +0000
Revision:
1:a000e0121191
Parent:
0:2f9e67d4c561
Child:
2:80464803bc2f
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CSTritt 1:a000e0121191 1
CSTritt 1:a000e0121191 2 /*
CSTritt 1:a000e0121191 3 File: main.cpp
CSTritt 1:a000e0121191 4 Project: ArrayLimits
CSTritt 0:2f9e67d4c561 5
CSTritt 0:2f9e67d4c561 6 //------------------------------------
CSTritt 0:2f9e67d4c561 7 // Tera Term configurations
CSTritt 0:2f9e67d4c561 8 // Terminal - New-line, Receive LF, Transmit LF
CSTritt 0:2f9e67d4c561 9 // Serial port - Data 8 bit, Parity none, Stop 1 bit data, Flow control none.
CSTritt 0:2f9e67d4c561 10 // Baud as specified below.
CSTritt 0:2f9e67d4c561 11 //------------------------------------
CSTritt 0:2f9e67d4c561 12
CSTritt 0:2f9e67d4c561 13 // Serial pc(SERIAL_TX, SERIAL_RX, 921600); // Highest Tera Term speed - works.
CSTritt 1:a000e0121191 14 // Serial pc(USBTX, USBRX, 115200); // Highest common speed - works.
CSTritt 0:2f9e67d4c561 15 // Serial pc(USBTX, USBRX); // Default 9600 baud, alternate pin names - works.
CSTritt 1:a000e0121191 16 */
CSTritt 1:a000e0121191 17 #include "mbed.h"
CSTritt 0:2f9e67d4c561 18
CSTritt 0:2f9e67d4c561 19 int main()
CSTritt 0:2f9e67d4c561 20 {
CSTritt 1:a000e0121191 21 float a[] {1.0, 3.0, 5.0, 7.0, 9.0 };
CSTritt 1:a000e0121191 22 printf("Hello World !\n");
CSTritt 1:a000e0121191 23
CSTritt 1:a000e0121191 24 for (int i = 0; i > -10; i--) { // Displays zeros and one NaN.
CSTritt 1:a000e0121191 25 printf("a[%d] is %f.\n", i, a[i]);
CSTritt 1:a000e0121191 26 wait(0.5f);
CSTritt 0:2f9e67d4c561 27 }
CSTritt 1:a000e0121191 28
CSTritt 1:a000e0121191 29 for (int i = 0; i < 10; i++) { // Hangs after 6th value!
CSTritt 1:a000e0121191 30 printf("a[%d] is %f.\n", i, a[i]);
CSTritt 1:a000e0121191 31 wait(0.5f);
CSTritt 1:a000e0121191 32 }
CSTritt 1:a000e0121191 33
CSTritt 1:a000e0121191 34 while (true) {}; // Just loop here forever after tests.
CSTritt 0:2f9e67d4c561 35 }