DigitalOut array bug?

13 Mar 2019

Hello,

I use Mbed LPC1768.

Today i fall on a bug with DigitalOut array when you try to write out of range.

If you initialize an array in first you dont have the same result with an array in last.

Like you can see beelow i had try on lots of compilers and the results change again.

array first

#include "mbed.h"

DigitalOut leds[] = {LED1, LED2};
DigitalOut out(p5);

int main()
{
    leds[-1] = 1;
    leds[0] = 1;
    leds[2] = 1;
    leds[1] = 1;
} 

Mbed OS Simulator -> LED1 and LED2 are ON

Mbed Online Compiler with mbed 2 -> LED1 and LED2 are ON

Mbed Online Compiler with mbedOS 5.9.7 -> LED1 and LED2 are OFF

Mbed CLI Compiler with GCC_ARM and mbedOS 5.9.7-> LED1 and LED2 are OFF

Mbed Studio Compiler with ARMC6 and mbedOS 5.9.7 -> LED1 blink and LED2 OFF

array last

#include "mbed.h"

DigitalOut out(p5);
DigitalOut leds[] = {LED1, LED2};

int main()
{
    leds[-1] = 1;
    leds[0] = 1;
    leds[2] = 1;
    leds[1] = 1;
}

Mbed OS Simulator -> LED1 and LED2 are ON

Mbed Online Compiler with mbed 2 -> LED1 ON and after a little delay LED1 blink and LED2 OFF

Mbed Online Compiler with mbedOS 5.9.7 -> LED1 ON and LED2 OFF

Mbed CLI Compiler with GCC_ARM and mbedOS 5.9.7-> LED1 and LED2 are OFF

Mbed Studio Compiler with ARMC6 and mbedOS 5.9.7 -> LED1 blink and LED2 OFF

I think Mbed CLI Compiler with GCC_ARM or ARMC6 give good results, isn't it? But why these differences...?

Thanks for your help, YSI

14 Mar 2019

Hi Seppo Takalo,

Thank you for your reply!

I understand what you are saying with a random occurrence when you are out of range in a table.

But in my mind, I had always associated any writing out of range to a crash of the board and I was very confused when the first code ran uninterrupted with the online compiler and mbed lib 2.0.