c - Incomplete Type is not allowed, 2 structs -
i know there million of these posts, i'm not sure how fix this. because elua_adc_ch_state defined above used again? lines err marked.
typedef struct { // status bit flags volatile u8 op_pending: 1, // there pending conversion? blocking: 1, // in blocking or non-blocking mode? (0 - blocking, 1 - nonblocking) freerunning: 1, // if true, don't stop when we've acquired requested number of samples smooth_ready: 1, // has smoothing filter warmed (i.e. smoothlen samples collected) value_fresh: 1; // whether value pointed value_ptr fresh unsigned id; u8 logsmoothlen; volatile u16 smoothidx; volatile u32 smoothsum; u16 *smoothbuf; volatile u16 reqsamples; volatile u16 *value_ptr; } elua_adc_ch_state; typedef struct { elua_adc_ch_state *ch_state[ num_adc ]; *** <---- volatile u16 sample_buf[ num_adc ]; *** <---- volatile u8 clocked: 1, force_reseq: 1, skip_cycle: 1, running: 1; // whether or not sequence running volatile u32 ch_active; // bits represent whether channel should converted on device volatile u32 last_ch_active; // keep copy of old configuration unsigned timer_id, seq_id; // timer bound device, sequencer device id volatile u8 seq_ctr, seq_len; } elua_adc_dev_state;
all of u16, u8, num_adc assignments defined , included. i'm not sure why second struct fails when first fine... no circular header dependencies either.
thanks
most issue variable length arrays flexible array members @ top of structure, not portable. rules on vlas flexible array members require (§6.7.2.1p3) @ end of structure definition:
typedef struct{ int foo; unsigned int bar; int foobar [] } barfoo;
i highly recommend not using vlas flexible array members exist in ansi c99 , optional in iso c11 (see §6.10.8.3) implemented more widely. the ansi standard not seem specify behavior using vlas in structures in c11 it's undefined behavior.
update:
per casey's comment below defined flexible array members (§6.7.2.1p18) have many cases of undefined behavior (§6.7.2.1p21) in standard , should avoided.
Comments
Post a Comment