user42225: How should I index HardwareSerial ports into a single array?.
This compiles, but do not work.
HardwareSerial Serials[]={Serial,Serial1,Serial2,Serial3};

void setup(){
    for (int i=0;i<=3;i++){
        Serials[i].begin(38400);
        while (!Serials[i]);
    }
}

char s;
void loop(){
    for (int i=0;i<=3;i++){
        if (Serials[i].available()){
            s=Serials[i].read(); 
            Serials[i].write(s); 
        }
    }
}


user37622: your code makes copies of Serials into items in the array of HardwareSerials. To use the original Serial objects, store and use pointers.
HardwareSerial* Serials[]={&Serial,&Serial1,&Serial2,&Serial3};

void setup(){
    for (int i=0;i<=3;i++){
        Serials[i]->begin(38400);
        while (!*Serials[i]);
    }
}

void loop(){
    for (int i=0;i<=3;i++){
        if (Serials[i]->available()){
            char s=Serials[i]->read();
            Serials[i]->write(s);
        }
    }
}


42225: <p>How should I index HardwareSerial ports into a single array?.</p>

<p>This compiles, but do not work.</p>

<pre><code>HardwareSerial Serials[]={Serial,Serial1,Serial2,Serial3};

void setup(){
    for (int i=0;i&lt;=3;i++){
        Serials[i].begin(38400);
        while (!Serials[i]);
    }
}

char s;
void loop(){
    for (int i=0;i&lt;=3;i++){
        if (Serials[i].available()){
            s=Serials[i].read(); 
            Serials[i].write(s); 
        }
    }
}
</code></pre>
 37622: <p>your code makes copies of Serials into items in the array of HardwareSerials. To use the original Serial objects, store and use pointers.</p>

<pre><code>HardwareSerial* Serials[]={&amp;Serial,&amp;Serial1,&amp;Serial2,&amp;Serial3};

void setup(){
    for (int i=0;i&lt;=3;i++){
        Serials[i]-&gt;begin(38400);
        while (!*Serials[i]);
    }
}

void loop(){
    for (int i=0;i&lt;=3;i++){
        if (Serials[i]-&gt;available()){
            char s=Serials[i]-&gt;read();
            Serials[i]-&gt;write(s);
        }
    }
}
</code></pre>
