c - 不允许使用不完整类型,2 个结构

标签 c compiler-errors

我知道此类帖子大约有一百万个,但我不知道如何解决这个问题。是不是因为上面定义了elua_adc_ch_state然后又使用了?错误的行已被标记。

typedef struct 
{
  // Status Bit Flags
  volatile u8     op_pending: 1, // Is there a pending conversion?
                  blocking: 1, // Are we in blocking or non-blocking mode? (0 - blocking, 1 - nonblocking)
                  freerunning: 1, // If true, we don't stop when we've acquired the requested number of samples
                  smooth_ready: 1, // Has smoothing filter warmed up (i.e. smoothlen samples collected)
                  value_fresh: 1; // Whether the value pointed to by value_ptr is 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 is running
  volatile u32        ch_active; // bits represent whether channel should be converted on this device
  volatile u32        last_ch_active; // keep copy of old configuration
  unsigned            timer_id, seq_id; // Timer bound to device, sequencer device id
  volatile u8         seq_ctr, seq_len;
} elua_adc_dev_state;

定义并包含所有 u16、u8、NUM_ADC 分配。我只是不确定为什么当第一个结构很好时第二个结构会失败...也没有循环头依赖项。

谢谢

最佳答案

最有可能的问题是结构顶部的可变长度数组灵活数组成员,它们并不是真正可移植的。 VLA 灵活数组成员的规则要求 (§6.7.2.1p3) 它们位于结构定义的末尾:

typedef struct{
   int foo;
   unsigned int bar;
   int foobar []
} barfoo;

我强烈建议不要使用VLA灵活数组成员,因为它们仅存在于ANSI C99中并且是optional in ISO C11 (参见第 §6.10.8.3) 实现得更广泛。 ANSI 标准似乎甚至没有指定在 C11 结构中使用 VLA 的行为,因此它可能是未定义的行为。

更新:

根据下面凯西的评论,它们被定义为灵活数组成员 (§6.7.2.1p18)然而,即使在标准中,它们也确实存在许多未定义行为的情况(§6.7.2.1p21),应该避免。

关于c - 不允许使用不完整类型,2 个结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17980236/

相关文章:

c - 在 C 语言中编码时,当输入被定向保存在整数变量中时,为什么会出现问题?

c - 将数组作为参数传递给 C 中的函数

arrays - 将MovieClips从舞台添加到阵列并播放它们

c - 增量关于TCC,GCC

c++ - 函数参数求值顺序

c++ - QRCodeSignature类不允许记录语句

c# - #在网络发布期间定义符号

python - 编译器问题: AssertionError on replace( ) given T or F condition with string and column cell

compiler-errors - 转让所有权(Genie/Vala)

c - 对 IEEE 754 的理解存在问题