cstructcompiler-errorsc89hi-tech-c

'error ";" expected' when initialising multiple structs


I have typdef'd a struct, and immediately below this I've simultaneously declared and initialised the variables I want using the typedef'd struct.

When I try to compile the code, there are no error messages relating to 'hi_aud', but the rest of the structs bring up the error 'error: ";" expected'. The array also brings up this warning, plus 'error: "}" expected'.

I'm using Hi-Tech C compiler v., which uses the C90 ANSI C standard.

/* Due to C90, do not change order of vars in struct or else code will explode
 */
typedef struct alarm {
    const uint_fast32_t pattern[];
    const uint_fast8_t size;
    void (*toggle)(void);
    void (*off)(void);
    bool on;
    bool init;
    uint_fast8_t pos;
    uint_fast16_t start;
    uint_fast8_t overflows;
};

static struct alarm hi_aud {
    [108, 27, 108, 20, 108, 12, 108, 5],
    sizeof(hi_aud.pattern) / sizeof(*hi_aud.pattern),
    &sounder_toggle,
    &sounder_off,
};

static struct alarm med_aud {
    [255, 50, 50, 255],
    sizeof(med_aud.pattern) / sizeof(*med_aud.pattern),
    &sounder_toggle,
    &sounder_off,
};

static struct alarm lo_aud {
    [255],
    sizeof(lo_aud.pattern) / sizeof(*lo_aud.pattern),
    &sounder_toggle,
    &sounder_off,
};

static struct alarm hi_vis {
    [255],
    sizeof(hi_vis.pattern) / sizeof(*hi_vis.pattern),
    &hi_vis_toggle,
    &hi_vis_off;
};

static struct alarm med_vis {
    [255],
    sizeof(med_vis.pattern) / sizeof(*med_vis.pattern),
    &med_vis_toggle,
    &med_vis_off,
};

static struct *alarms = {&hi_aud, &med_aud, &lo_aud, &hi_vis, &lo_vis};
static uint_fast8_t alarms_siz = sizeof(alarms) / sizeof(*alarms);

edit When I use the '{}' brackets to initialise the array, another error "error: no identifier in declaration" comes up. This does not happen when I use the '[]' brackets.


Solution

  • Inside a strcut's defintion the elements' defintions are separated by ; not be ,. not the issue :}