I have isolated a very strange behaviour down to a few lines in a simple Duemilinova program. If I try to set a structure element, the program will compile and download, but it will not run. I know something is not working because the LED never blinks as the setup program is waiting for a user to press a key.
I did some research and found the bug list and only one is similar to what I am seeing. I tried the workaround (using an intermediate pointer) but that did not work.
I hope that some of you might try out the various test cases in this code (see the TEST #define) and tell me what might be the problem. Code follows.
#define NUM_THING 16 // Number of B structures
#define NUM_A 5 // Number of A structures
#define PIN_LED 13 // PIN ID for the LED on an Arduino Duemilinova
// A structure that will be nested
typedef struct {
char a_aaa[15+1];
int a_bbb;
int a_ccc;
int a_ddd;
} A_t;
// Another structure (B)
typedef struct {
char b_eee[15+1];
A_t b_fff[NUM_A];
} B_t;
// An instance of the top level structure (B)
B_t thing[NUM_THING];
#define TEST 5
//********************************************************************
//
// This gets executed before anything else
//
//********************************************************************
void setup() {
int i;
void *p;
// Initialize the IO pins
pinMode(PIN_LED, OUTPUT);
// Open serial port
Serial.begin(9600);
// Wait till user enters a key
Serial.println("");
Serial.println("Type a key to start");
do {
digitalWrite(PIN_LED, HIGH);
delay(250);
digitalWrite(PIN_LED, LOW);
delay(250);
} while (!Serial.available());
Serial.println("Starting");
// Fails
#if TEST == 1
strcat(thing[0].b_eee, "aaa");
#endif
// Fails
#if TEST == 2
p = &thing[0].b_eee;
strcat((char*)p, "aaa");
#endif
// Works
#if TEST == 3
p = &thing[0].b_eee;
#endif
// Works
#if TEST == 4
strcat((char*)p, "aaa");
#endif
// Fails
#if TEST == 5
thing[0].b_fff[0].a_bbb = 1;
#endif
} // end Setup
//********************************************************************
//
// Main loop
//
//********************************************************************
void loop() {
delay(500);
Serial.println("loop");
} // end loop