incomplete type is not allowed

Posted htsky

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了incomplete type is not allowed相关的知识,希望对你有一定的参考价值。

keil环境下,报错#70: incomplete type is not allowed,解决

mqtt_conf.h 定义了一个结构体

mqtt_buffer.h

#include <stdint.h>
#include "mqtt.h"

定义了一个结构体

struct MqttBuffer
{
struct MqttExtent *first_ext;
struct MqttExtent *last_ext;
uint32_t available_bytes;
char **allocations;
char *first_available;
uint32_t alloc_count;
uint32_t alloc_max_count;
uint32_t buffered_bytes;
};

c.h

#include <stdint.h>
#include <time.h>
#include "mqtt_conf.h"
#include "mqtt_buffer.h"

  定义了一个结构体

struct MqttSampleContext
{
uint32_t sendedbytes;
struct MqttBuffer mqttbuf[1];
struct MqttContext mqttctx[1];
const char *proid;
const char *devid;
const char *apikey;
int dup;
enum MqttQosLevel qos;
int retain;
uint32_t publish_state;
uint16_t pkt_to_ack;
char cmdid[MQTT_LEN_MAX];
};

编译报错如下:

..\User\mqtt.h(189): error:  #70: incomplete type is not allowed

      struct MqttBuffer mqttbuf[1];

搜索了很多文章,没有找到原因。

后来 受到下面这个链接的启发,原来在mqtt_buffer.h 多了#include "mqtt.h"。原来在a.h里的内容比较少,我将内容搬到mqtt.h里了,所以才加了这句。恢复回去,就好了。

http://zhidao.baidu.com/link?url=HTiXra-5HCPCfj0_VleRYX5s9aDKBLnZjRBOEahUDPMF6u2CYBJ2yuxlaXIZZfihkRl1eWPUJZE-9JAXcmzrZq

结论,#include 的文件之间最好是单向的关系。在功能划分的时候,应尽量避免这个问题。keil的c跟标准的c似乎有些区别,很多时候没用 extern关键字反而没啥问题。

以上是关于incomplete type is not allowed的主要内容,如果未能解决你的问题,请参考以下文章

CDH大数据平台 安装superset常见错误汇总Could not import the lzma module. Your installed Python is incomplete

错误提示:The project was not built since its build path is incomplete. Cannot find the class file for ja

(Xaml) Type 'DeviceA' is not defined.

API 端点返回 TypeError: 'type' object is not iterable

python: "TypeError: 'type' object is not subscriptable"

remote staging type or host is not specified