Hi, I'm having a bit of trouble with a macro. Is it possible that having a macro that refers to another macro which in turn referes to another macro and so on, too many times, can cause problems for the compiler? I'm cross compiling using AVR GCC, so I guess the compiler is gcc or some port of it. Anyway, here is the macros I got:
Code:
typedef uint8_t servo_time;
#define NUM_SERVO_TIME_BYTES (sizeof servo_time)
...
#define SERVO_DATA_MSG_LEN (1 + NUM_SERVOS * NUM_SERVO_TIME_BYTES)
...
#define MAX_MSG_LEN SERVO_DATA_MSG_LEN
...
#define I2C_MAX_DATA_LEN MAX_MSG_LEN
NUM_SERVOS is an enum. When the program gets down to these rows:
Code:
if (read_buf->data_len < I2C_MIN_DATA_LEN ||
read_buf->data_len > I2C_MAX_DATA_LEN)
{
I get: "error: expected expression before 'servo_time'" at the second rows. However, when I replace the definitions with what they are defined as, i.e.:
Code:
if (read_buf->data_len < I2C_MIN_DATA_LEN ||
read_buf->data_len > (1 + NUM_SERVOS * (sizeof servo_time)))
{
the problem ceases to exist. Anybody has any idea of why?