digitalWrite(-1, HIGH)

hello everyone, I had an idea: what would happen if I tried to make pin -1 high during runtime? I tried to figure it out with this code:

int myPin;
char incomingByte[50];
int change=0;
int data=-1;
int l=0;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  

}

void loop() {
         // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte[l] = (char)Serial.read();
                if(incomingByte[l-1]=='-' && incomingByte[l]=='1')
                {
                  digitalWrite(13, HIGH);
                  change=-1;
                  digitalWrite(change, HIGH);
                  data=digitalRead(change);
                  Serial.print("data: ");
                  Serial.println(data);
                }
                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte);
                l++;
        }
}

When I uploaded it to my Uno I expected it to crash in some way, but instead it acted normal. Why?

thank you,
popa

How do you know it was “acting normal” ? Did you test pin -1 ?

One of the first things digitalWrite() does is ignore out-of-range pin numbers.

In C, the convention is that 0 is a logical false, anything else is a logical true. This is the way the logical operators !, &&, ||, and ?: work as well as the if, while, and do/while statements.

This is what allows code like this

char ch;
while(ch = *p++) {
  // do something with character ch
}

to work.

I haven't checked it, but I imagine that the arduino digitalWrite() function would follow this convention.