I want to use an element of an array (in this case element 3) as a loop variable giving it a simple name like "c". (This code is for the Arduino, but should look similar in standard C.) The question is: is there any way to make the compiler accept the c = 5 statement in the for-loop?
byte array[5];
#define c (int) (byte *) array[3]
void setup() {
Serial.begin(9600);
Serial.println("this only works with a work-around:");
Serial.print("address of array: ");
Serial.println( (int) &array );
Serial.println("this is the loop:");
for ( /* what you want is: c = 5 */
/* what the compiler requires: */ array[3] = 5;
c < 10; c++) Serial.println(c);
// the compiler does not accept c = 5
Serial.println("this works but it wasts time:");
while (c != 5) c++;
for ( ; c < 10; c++) Serial.println(c);
}
void loop() {
}
#define c ((int) array[3])